I wrote this query :
SELECT *
FROM etape_prospection INNER JOIN type_prospection
ON etape_prospection.type_prosp_id = type_prospection.type_prosp_id
WHERE etape_prospection.prosp_id IN (select transfert.prosp_id
from transfert
where transfert.user_code ='3'
AND transfert.date_transfert='2012-01-20');
My boss doesn’t like this query because of the IN keyword which makes a full table scan , so how to rewrite it without the IN keyword ?
You can use
EXISTSinstead ofINthis is usually cheaper thanINand sometimes also cheaper than theINNER JOINsuggested in other answers:Also (reminded by the comment by danihp on one of the other answers): using
INNER JOINcan have the unwanted/unintended side effect of duplicating rows in the resultset if there are multiple rows intransfertthat satisfy these conditions.