1

PDO::fetch() LIMIT 1

The above stack overflow post had a up-voted answer said yes but when I look at the comment, the discussion brought me a degree of curiousness. Where it mentioned

"If you use LIMIT row_count with ORDER BY, MySQL ends the sorting as soon as
it has found the first row_count rows of the sorted result, rather than
sorting the entire result."

which is a reference at http://dev.mysql.com/doc/refman/5.0/en/limit-optimization.html

That is only the case of if we use ORDER BY in the query, but not simply applied to SELECT and FETCH a row.

So my question is fetch equivalent limit 1 in a simple SELECT and fetch statment?

Community
  • 1
  • 1
Andrew
  • 2,810
  • 4
  • 18
  • 32

1 Answers1

0

No it's not equivalent, because a simple SELECT will not be guaranteed to order the results in any specific way, like it does when you specify an ORDER BY clause. Without the ORDER BY, the query is (usually) much quicker than when using ORDER BY. You can still use LIMIT without using ORDER BY of course, and it will (usually) return your smaller result set more quickly. But the performance benefits aren't as great, since there's no sorting being done at all in that case.

Rylab
  • 1,236
  • 7
  • 17