Return just the first result of mysql Query Return just the first result of mysql Query database database

Return just the first result of mysql Query


explain plan will always show 58, because is number of records which match you criteria.

However LIMIT 1 is all you need.


You can use EXISTS as such:

SELECT EXISTS(SELECT 1 FROM foo_table WHERE foo=<foo_id>).

The SELECT is ignored as EXISTS only checks the WHERE clause. As it is good practice to avoid using *, it is substituted by 1 here.

Here is the Documentation.


LIMIT 1 is the way to go, so you already found the solution yourself:

SELECT 1 FROM foo_table WHERE foo = ? LIMIT 1