“SELECT TOP 1 1” VS “IF EXISTS(SELECT 1”

I’d recommend IF EXISTS(SELECT * ...), unless this is actually causing a performance issue. It expresses the intent of the query in a much better understood fashion than alternatives.

I’d avoid COUNT(*) (as in the current answers) unless you actually need the count of rows from the table.

If you want the “efficiency” of checking the rowcount from the result, I’d probably go for:

select 1 where exists(select * from BigTable where SomeColumn=200)

Which produces the same result set as your second query (either 0 or 1 row)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)