In most cases, COUNT(*)
faster than COUNT(id)
in MySQL (due to how query groupings are performed with COUNT()
, it can be optimized in future versions, so both versions work the same way). But if you want to find at least one line, you can use EXISTS
simply:
( SELECT COUNT(id) FROM table_name ) > 0
bit faster:
( SELECT COUNT(*) FROM table_name ) > 0
much faster:
EXISTS (SELECT * FROM table_name)
source share