It varies from database to database, especially if compared columns
- indexed or not
- nullable or not
... but usually, if your query does not use the columns from the table you joined, you should use either IN or EXISTS :
SELECT e.id, e.begin_on, e.name FROM EVENTS e WHERE EXISTS (SELECT NULL FROM CONTACTS c WHERE ( c.contact_id = '1' AND c.user_id = e.user_id ) OR ( c.user_id = '1' AND c.contact_id = e.user_id )
Using a JOIN (INNER or OUTER) can overstate records if the child table has more than one record per parent table record. This is good if you need this information, but if not, you need to use either GROUP BY or DISTINCT to get a set of unique result values, and this may cost you when viewing the cost of a request.
EXISTS
Although EXISTS clauses look like correlated subqueries, they are not executed as such (RBAR: Row By Agonizing Row). EXISTS returns a boolean based on the provided criteria and leaves the first instance, which is true - this can make it faster than IN when working with duplicates in a child table.
source share