开发者

How to check that at least one row complies to a condition (WHERE clause) in MySQL?

开发者 https://www.devze.com 2023-01-20 13:28 出处:网络
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 jus

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
0

精彩评论

暂无评论...
验证码 换一张
取 消