NDaphid
01-08-2004, 10:31 PM
Hi,
Is it possible to speed up my SQL query by having it return the first match (in my "where" clause), then stop searching?
Thanks!
mikechan8888
01-08-2004, 10:45 PM
What database are you using? For SQL Server, try this:
SELECT TOP 1 field1, field2
FROM Table1
WHERE field1 = 123
Mike
NDaphid
01-08-2004, 10:47 PM
What database are you using? For SQL Server, try this:
SELECT TOP 1 field1, field2
FROM Table1
WHERE field1 = 123
Mike
Excellent! Thank you.
mikechan8888
01-08-2004, 10:52 PM
But don't forget if you include the ORDER BY clause in the SQL statement, you will get the same result but the whole record set will be built before returning the first matched record to you. So there will be no performance gain in that case.
Mike