DEV Community

Cover image for Use EXISTS instead of COUNT > 0 when checking if records exist

Use EXISTS instead of COUNT > 0 when checking if records exist

Luka Peharda on February 14, 2024

TL;DR Use exists when querying if SQL records exists instead of using count. exists is much more efficient and breaks out of the loop when first re...
Collapse
 
yassineche profile image
Yassine Cheddadi

Is this withExists method new ?!

Collapse
 
lukapeharda profile image
Luka Peharda

Since Laravel v8. As that is couple years old now, I'd say no :)