This MySQL subquery drives me nuts
Basically this is what I am trying to do here:
SELECT * FROM Table1 WHERE Table1.col1 = ‘bob’ AND Table1.col3 IN (SELECT Table2.col2 FROM Table2 WHERE Table2.col1 = ‘alice’)
Both Table1 and Table2 have the same column with the name “col1″. And the value of Table1.col3 should match values coming from Table2.col2.
However the query always returns empty set, even there are definitely data matches via the IN where clause. As a matter of fact, if I use the values directly from the subquery the whole query would work.
At a first glance, this looks like a correlated subquery issue but it’s not. Even Table1 and Table2 share the same column name, the subquery is not referring to any Table1 column in the where clause, so it shouldn’t be an issue explained here.
Anyone has some insight on this?