Link to home
Start Free TrialLog in
Avatar of Eligio
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!
ASKER CERTIFIED SOLUTION
Avatar of pfaires
pfaires

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Lowfatspread
Lowfatspread
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial