|
-
May 11th, 2006, 03:56 AM
#1
Thread Starter
Lively Member
IN query
Hi All,
How can I better replace the IN(....) to a better code?
SELECT TOP 1 MIN(table.Item), MIN(table.Post), MIN(table.add), MIN(table.creator), MIN(table.datecreated) FROM table WITH (NOLOCK) WHERE table.code IN('0012','0013','0014').
The above has causes some performance and system run time error issue especially within the IN bracket the table code gets very large. Please advise.
Thanks.
Last edited by skyseh; May 11th, 2006 at 04:16 AM.
-
May 11th, 2006, 06:31 AM
#2
Re: IN query
If this is actual range of codes then:
WHERE table.code Between '0012' and '0014'
But I also cannot understand how that query will run at all - MIN() aggregate functions mixed with TOP 1 makes no sense.
The query should be:
Code:
SELECT MIN(table.Item), MIN(table.Post)
, MIN(table.add), MIN(table.creator), MIN(table.datecreated)
FROM table WITH (NOLOCK)
WHERE table.code Between '0012' and '0014'
btw - is table.code a INDEX column on your table? How many rows in the table?
-
May 20th, 2006, 12:30 PM
#3
Re: IN query
Also dont forget that you can nest your Select statements. You can use a select statement to select the numbers you want in your IN statement....
Code:
SELECT ... FROM table WHERE Something IN (SELECT IDS From ... Where ... etc).
As long as the nested select contains the data that you are wanting in your IN statement, then it should work. In the above, this means as long as the nested select selects just the numbers...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|