So what IS the best way to check if a row exists? EXISTS, COUNT or num_rows?

前端 未结 3 1125
情深已故
情深已故 2021-02-15 04:05

If your only goal is to check if a row exists in php (true or false), what is the best way to do it?

Option 1?

$result          


        
3条回答
  •  你的背包
    2021-02-15 04:35

    The EXISTS is faster then SELECT COUNT(*) because the subquery will stop searching when it finds one row. It won't have to find them all and count them. It will return either 0 or 1:

    SELECT EXISTS 
           ( SELECT * FROM ... )
    

提交回复
热议问题