How to check that at least one row complies to a condition (WHERE clause) in MySQL?
The task is to have a query returning 0 if no rows are going to be returned if the condition is applied and 1 if there are going to be more than 0 rows. Preferably this query should be faster than just querying the table with the condition and limiting t开发者_如何学Gohe query with 1 row in result set.
select case
when exists (
select *
from MyTable
where MyColumn = 23
) then 1
else 0
end as RowsExist
精彩评论