I have the following query:
select *
from Table1
where NUMid in (select NUMid
from Table2
where email = '[email protected]')
My intention is to get the list of all the NUMids from table2 having an email value equal to [email protected] and use those list of NUMids to query from Table1. When I directly put the list of NUMids (which have the email = [email protected]) within the IN clause, the data scanned is very less. For example:
select *
from Table1
where NUMid in (123,456,789,345)
But if run the first query where the inner query also gives a list of NUMids then the data scanned is very large.
Even though logically both the queries are the same, why is there such discrepancies? ** The subquery is a small table in my case and scans only few kbs, so I am assuming it should not contribute to high data scan