SQL: How to properly check if a record exists

前端 未结 9 1343
粉色の甜心
粉色の甜心 2020-11-28 01:23

While reading some SQL Tuning-related documentation, I found this:

SELECT COUNT(*) :

  • Counts the number of rows.
  • Often is improper
9条回答
  •  旧时难觅i
    2020-11-28 02:18

    I'm using this way:

    IIF(EXISTS (SELECT TOP 1 1 
                    FROM Users 
                    WHERE FirstName = 'John'), 1, 0) AS DoesJohnExist
    

提交回复
热议问题