开发者

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
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜