Eligio
asked on
SELECT COUNT vs SELECT ... LIMIT
Hi experts.
My doubt is quite general. I usually develope with SQL Server and My-SQL.
I want to know if there is ANY row that match the search. No matter in how many are there.
a) SELECT COUNT(colname1) FROM Foo WHERE colname2 = 'something' AND colname3 = 1;
b) SELECT colname1 FROM Foo WHERE colname2 = 'something' AND colname3 = 1 LIMIT 1;
Does first one need a full table scan? May be the second one faster, because it stops when the first match is found?
Thanks!
My doubt is quite general. I usually develope with SQL Server and My-SQL.
I want to know if there is ANY row that match the search. No matter in how many are there.
a) SELECT COUNT(colname1) FROM Foo WHERE colname2 = 'something' AND colname3 = 1;
b) SELECT colname1 FROM Foo WHERE colname2 = 'something' AND colname3 = 1 LIMIT 1;
Does first one need a full table scan? May be the second one faster, because it stops when the first match is found?
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.