two tables:
== customers ==
cust_id
== attachments ==
att_id
cust_id
1 customer -> MANY attachments
i would retrieve all the custmers and, adding the boolean virtual field “has_attach” to select, know if a customer have got attachments.
without GROUP BY, if this is possibile 🙂
Depending on how many
manyreally means, theCOUNT(*)option can impose an un-necessary burden.In which case, the following can sometimes yield benefits.
This is because
EXISTSdoesn’t actually read all the records. It just checks that any record exists.In fact, when using indexes this doesn’t even read any records from the table. It just checks that the index points to any matching records and stops there.