query

SQL Server query - find first in sequence

Let's say I have the following example table GroupID ItemID Created ----------------------------------------------- A ABC 5/1/2009 13:02 A XZY 5/1/2009 13:01 A LMO 5/1/2009 13:03 A DEF 5/1/2009 13:00 A PQR ...

Add record only if doesn't exist in Access 2007

I have a table, let's say it stores staff names (this isn't the exact situation, but the concept is the same), and the primary key is set to an autonumber. When adding a a new member of staff I want to check to see if that name exists in the database before it is added, and maybe give an error if it already exists. How can I do this from...

How to use outer query's columns in subqueries?

I have a table with inventory records and another table with documents describing each inventory records, something like: inventory (t1) t1id t1c1 1 desc1 2 desc2 3 desc3 documents (t2) t2id t2c1 t1id 1 doc1 1 2 doc2 1 3 doc3 2 4 doc4 3 so i try this que...

Does order of boolean statements make a performance difference in a MySQL query?

Suppose I want to query a table based on multiple WHERE clauses. Would either of these statements be faster than the other? SELECT * FROM table WHERE (line_type='section_intro' OR line_type='question') AND (line_order BETWEEN 0 AND 12) ORDER BY line_order"; ...or: SELECT * FROM table WHERE (line_order BE...

ASP.NET Query with parameters

Please help me, I don't know what can be wrong with the following code: OdbcConnection conn = new OdbcConnection(connString); String query = "INSERT INTO customer (custId, custName, custPass, "+ "custEmail, custAddress, custAge) VALUES (" + "@ID, @Name, @Pass, @Email, @Addres...

MySQL query execution return value?

Hi, I'm constructing an adapter for MySQL in PHP and I was wondering what should MySQL query execution method return? Should it return a result set? Or the last id / affected rows? ...

to modify a query in access

Hi, I have a query which gives a result like this field1 field2 field3 field4 field5 23 gfhf ghjj 5 49 23 ghf jkll 6 45 67 bnvn nmb 7 45 89 gfh hjj 8 78 89 gfhg hk 9 23 Here the first 2 and last 2 records are kind of sa...

Sql Query Group a range of numbers with low's and high's

Hi all, I have a table that looks something like below street_id | address_number | address_direction | address_street | address_type ... ---------------------------------------------------------------------------------- 1 | 121 | W | Fake | St 1 | 131 | W ...

SQL query with count and case statement

i need to find how many people have filed (fil_dt) their tax return within 60 days, withing 120 days, within 180 days, over 180 days of their filing period end date (fpe) for 3 different years (2006, 2007, 2008) the statement below will give me ALL years i need a count for each year and for each possibility.. anyway i can do this withou...

using aggregate function with more than two columns

I have two tables, stats and stat_log. The stat log is like this: user_id,stat_id,value,registered and It logs the value of the stats for the given times. I need every last value from every stat for a given user. So i want something like this, but with values: select stat,max(registered) from stat_log where uid = 1 group by stat; ...

MySQL: optimizing a JOIN query

Say I have two MyISAM tables: tab_big: id1, id2, id_a, ord (5 billion records) tab_small: id1, id2, id_b (1 billion records) CREATE TABLE IF NOT EXISTS `tab_big` ( `id_a` int(10) unsigned NOT NULL, `id1` int(10) unsigned NOT NULL, `id2` int(10) unsigned NOT NULL, `ord` int(10) unsigned NOT NULL DEFAULT '...

Insert, Update, Delete for Oracle are not working in .NET C#?

It has been a while that i'm dealing with oracle and .net and they don't seem to be a perfect match together. That's this strange thing, i'm not finding any reason why it happens or how to fix it. I do simple insert, update and delete and they are not working. It fails on the cmd.ExecuteNonQuery(); Here's the piece of code: sqlComm...

A little fuzzy on getting DISTINCT on one column?

I've seen a few different versions of this question but having difficulty applying it to what I need... MS SQL Server 2008 query: SELECT Receipts.ReceiptID, Receipts.UserID, Receipts.UserCardID, FolderLink.ReceiptFolderLinkID FROM dbo.tbl_ReceiptFolderLnk AS FolderLink INNER JOIN dbo.tbl_Receipt AS Receipts ON FolderLink.ReceiptID...

Oracle comparison issue

I'm trying to compare two columns from different columns. Ex: Select a.Col1, b.Col1, CASE WHEN a.Col1 <> b.Col1 THEN 'TRUE' ELSE 'FALSE' END CASE FROM TableA a LEFT OUTER JOIN TableB b ON a.id = b.id I always get false but not true even though they are different or if there is a value in TableA and not in TableB. What is wrong with ...

Tricky SQL query

Hello guys! Really tricky SQL statement I have here. Trying to build this query for about hour. Maybe You can help me. We have a table with 3 columns: gamename | user | times_played The query should select top three games (depending total times_played) and top three user who has played most times in this game => 9 rows. The result is...

How do I search set of keywords from keywords field in Solr?

So I have a keyword field with this schema Indexed, Tokenized, Multivalued, TermVector Stored, Omit Norms then I wanna search set of keywords against it like q=keyword:keyword1, keyword2, keyword3, etc, etc and want to return most matching keywords, even 1 match keyword is fine, but ordered by most match. thank you ...

nhibernate cross table query optimization

I have a query I've written with NHibernate's Criteria functionality and I want to optimize it. The query joins 4 tables. The query works, but the generated SQL is returning all the columns for the 4 tables as opposed to just the information I want to return. I'm using SetResultTransformer on the query which shapes the returned data t...

MySQL - Query All users WITHOUT an appointment

If I have two tables: Users and Appointments. How would I query the db to find something like the following: SELECT * FROM users WHERE (none of: appointments.user = user.id) I am assuming I would need some type of join with the appointments table, just not sure where to start. ...

I want to show records from a table having a date column from sqldatabase in dates order. How should I?

I want to show records from a table having a date column from sqldatabase in dates order. How should I? ...

SQL ORDER BY date problem

Can you please help me in solving this problem. I am trying to order the results of an SQL query by date, but I'm not getting the results I need. The query I'm using is: SELECT date FROM tbemp ORDER BY date ASC Results are: 01/02/2009 03/01/2009 04/06/2009 05/03/2009 06/12/2008 07/02/2009 Results should be: 06/12/2008 03/01/2009 ...