database-queries

MySQL Query Performance on Calendar Database

Hello all. I am creating a calendar webapp and I'm kinda stuck between a performance vs storage issue in the creation and subsequent queries of my events table. The concept is "how to make a table with repeating events (daily/weekly)?" Here is my current solution: CREATE TABLE `events` ( `eventid` int(10) NOT NULL AUTO_INCREMENT, ...

Am I the only one that queries more than one database?

After much reading on ruby on rails and multiple database connections, it seems that I have found something that not that many folks do, at least not with ror. I am used to querying many different databases and schemas and pulling back the information either for a report or for one seamless page. So, a user doesn't have to log on to se...

MySQL: Updating a left-joined view, where right table has no matching data.

I'm curious to know if this is actually possible... In this simplified example, I have: Table_A: Table_B: +------+--------+ +------+--------+ | id | data_1 | | id | data_2 | +------+--------+ +------+--------+ | 1 | Hello | | 1 | There | +------+--------+ +------+--------+ | 2 | Hi | +------+--------+...

Need Help with queries (views) in Microsoft Access

I have an application that records weight of a bin holding items in inventory into a Microsoft Access Table Like so: Id(AutoNumber) Timestamp Weight ------------------------------------- 1 Jan 1 1 2 Jan 2 1 3 Jan 3 2 4 Jan 4 2 5 ...

How to test MySQL query speed, with less inconsistencies?

I need a simple way to test SQL queries for speed. I am not to worried about hardware differences, I basically need a relative number. This is what I've been doing with PHP (its fuzzy, but works): // CONNECT TO DB HERE $sub = new YomoSubscription(95,783); $t = microtime(TRUE); // contains the SQL db call i'm testing $fp = $sub->gen...

CakePHP array structure from a HABTM query.

I have two tables linked via a HABTM. countries & networks. They are linked together by the countries_networks lookup table. I need to get all of the countries and all of the associated network ids for each corresponding country. I don't need to go as far as getting the network names, simply getting the ids from the lookup table will su...

how to loop over looped elements?

I'm creating a tree-structure of categories with parentid's which can be called from children in such a way: ID | Name | ParentID 1 1 0 2 2 1 3 3 2 4 4 1 Resulting in this: 1 = 1 2 = 1 -> 2 3 = 1 -> 2 -> 3 4 = 1 -> 4 which means 3 is a child of 2, which is a child of 1. when trying to get this idea ...

Which of these two DB designs will lead to faster queries?

Which will be faster, what will the answer depend on: 1) Looking up a numerical id in a DB table A, and then querying another table B for all instances of that numerical ID. where table B is likely to be 100x larger. 2) Querying table B directly using for the string in question. Now that I write this I think intuitively solution 1 is ...

MVC using Linq to Entity w/ sql encryption

Currently i am using sql encryption and would like to continue using it through Linq. I have all my CRUD stored proc's created and wired up to the table in the model in order to handle the encryption/decryption through sql. Main problem is that my database model see's a field type of varbinary(max) which is used for the sql encryption ...

How to select all values, not just those in where clause

I have a query that looks like this: SELECT id, GROUP_CONCAT(type SEPARATOR ',') AS type FROM rock_types WHERE type IN("DWS","Top rope") GROUP BY id this returns all the ids that have a type of DWS or top rope or both with the types concatenated. However, there are more types than just those 2. Is it possible to still select ...

Excel: Use a cell value as a parameter for a SQL query

I'm using MS Excel to get data from a MySQL database through ODBC. I successfully get data using an SQL query. But now I want that query to be parameterized. So I wonder If it is possible to use a cell value (a spreadsheet cell) as a parameter for such a query. For example, for this query: select name from user where id=1 I'd like to ...

Using SUM so that NULL in columns make sum NULL

I have a a table with a column groups INTEGER NULL. It has values groups 5 7 <NULL> If I do a select sum(groups) form table_name I would get 12. How can I get null, when the column being summed has a null. ...

PHP/SQL - Hard SELECT question..

I am creating a calendar application. In the Events table, there are two columns, a start and end timestamp. EVENTS - { start_timestamp, end_timestamp } I have two variables in my PHP application. One is the timestamp of the beginning of a month, another is the timestamp of the end of a month. I want to select from the events table ...

How should a C# windows app interact with a database when atomically dealing with large sets of data

One of my co-workers is building a C# windows app that needs to grab a set of data and then row-by-row alter that data. If the system encounters a problem at any step in the process, it needs to roll back all of the changes. The process he has created works well when dealing with smaller sets of data, but as soon as the number of rows g...

Order a query based on a field pointing to the same table

Hi all, I have a table called "Sentence" that has the following fields: ID <--- OK NextID <--- FK To ID Text So if I had the following records: *ID* *NextID* *Text* 1 12 The quick 3 40 jumps over 5 null lazy dog. 12 ...

Hibernate or JDBC

I have a thick client, java swing application with a schema of 25 tables and ~15 JInternalFrames (data entry forms for the tables). I need to make a design choice of straight JDBC or ORM (hibernate with spring framework in this case) for DBMS interaction. Build out of the application will occur in the future. Would hibernate be overki...

Select returns 0 rows in a cursor and right number of rows in manual running

Hello: I've this cursor declaration: DECLARE CursorArticulo CURSOR FOR SELECT HstAt.IdArticulo, SUM(HstAt.Cantidad) As SumaCantidad, HstAt.Precio FROM HstArticulosTickets hstAT INNER JOIN HstTickets HstT ON hstAT.IdTicket=hstT.IdTicket WHERE hstT.NumUsuarioEmisor=@UsuarioAct ...

What indexes can be used to improve this query?

This query selects all the unique visitor sessions in a certain date range: select distinct(accessid) from accesslog where date > '2009-09-01' I have indexes on the following fields: accessid date some other fields Here's what explain looks like: mysql> explain select distinct(accessid) from accesslog where date > '2009-09-01'; ...

MYSQL select "all" of the values rather than "any" of them?

Hello this SQL statement "select firstname,lastname from users where lastname in('foo','bar') group by firstname" it means select all records in table "users" where lastname match any of the "foo" or "bar" I don't want this behaviour what I want to retrieve is all records in "users" table where lastnames match all of "foo" and "b...

PostgreSQL and Sequential Data

I have a dataset that contains: Table { date itemName } The date for the most part is sequential. There are no duplicates of the date [as it is the primary key]. The question is split up into multiple parts (all with respect to using SQL): Is it possible to find gaps in the date series listed in the table? For example: Dates 1/2/09...