tags:

views:

30

answers:

1

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 the query with 1 row in result set.

+1  A: 
select case 
        when exists (
            select * 
            from MyTable 
            where MyColumn = 23
        ) then 1 
        else 0 
    end as RowsExist
RedFilter