To Find if a record exists or not:

Normally we use : SELECT COUNT(*) FROM anj_table WHERE fileldName = ‘anj_field’

Instead use sub-query

SELECT EXISTS (SELECT 1 FROM `anj_table` WHERE fieldName = ‘anj-value’ )

It executes faster than SELECT COUNT(*) to get if a particular row exists or not.

Reason being sub-query stop executing when it finds very first match.

Leave a Reply

Your email address will not be published. Required fields are marked *