Changing IN to EXISTS in SQL
sql
Solution
You need to match the two columns that will be used in the `exists` together:
select
t1.a, t1.b
from
table1 t1
where
exists (select 1 from table2 t2 where t2.c = t1.a)
The reason why you have to do that, is because `exists` performs a semi-join on the table, and therefore, needs to have a join condition.
Problem
I have the following query: ``` select A, B from table1 where A in (select c from table 2 ) ``` But, now I need to change this query and use `exists` instead of `in`, and it should give the same results. My tables look like the following: ``` table1 table2 A B c ------ ----- 1 x 1 2 y 3 3 z 4 4 w 7 5 a 1 b ``` How do I use the `exists` function?