I have this query to retrieve rows from table r which do not have a corresponding entry in the table ra.
Code:
SELECT name, r_id FROM r WHERE r_id NOT IN (SELECT r_id FROM ra GROUP BY r_id);
This one is taking about 8 seconds to execute.
On the other hand, this query
Code:
SELECT r.name, r.r_id FROM r 
LEFT JOIN ra on r.r_id = ra.r_id
WHERE ra.r_id is NULL;
is taking less than a second.
Can you explain the reason for the difference in time taken?
Thank you.