tags:

views:

31

answers:

2

Assuming the query

SELECT * FROM table WHERE a='1' and b='2' and c>'3' and d>'4' and e!='5' and f='6'

returns 10000 results.

My question is, let's say I limit the search to the first 10 results like this:

SELECT * FROM table WHERE a='1' and b='2' and c>'3' and d>'4' and e!='5' and f='6' LIMIT 10

Will mysql search through all the 10000 results or it will stop at the 10th result?

+1  A: 

LIMIT will only display the rows specified, based on their position within the resultset. Without an ORDER BY, you're relying on the order the records were inserted.

You'll probably be interested to read about MySQL's ORDER BY/LIMIT performance...

OMG Ponies
The order actually depends on storage engine used. Also, MyISAM tables can be sorted 'on disk'. In general it is true, that the order is unreliable.
Mchl
A: 

Since there is no ORDER BY, it will stop at the 10th result (after going through as many non-matching rows as necessary). As OMG Ponies says, which 10 rows you get is unspecified.

Justin K