Best way to test if a row exists in a MySQL table

后端 未结 12 2083
小蘑菇
小蘑菇 2020-11-22 06:11

I\'m trying to find out if a row exists in a table. Using MySQL, is it better to do a query like this:

SELECT COUNT(*) AS total FROM table1 WHERE ...
         


        
12条回答
  •  死守一世寂寞
    2020-11-22 06:35

    Suggest you not to use Count because count always makes extra loads for db use SELECT 1 and it returns 1 if your record right there otherwise it returns null and you can handle it.

提交回复
热议问题