Reputation: 31
I have two table created as
create table table1(id int,);
create table table2(id int, tb2_id int,...)
But when i try out
Select * from table2 where tb2_id=table1.id;
I have got an error that table1.id is an unknown column.
Could someone point out where the mistake I made is ?
Upvotes: 1
Views: 1292
Reputation: 263933
try this:
SELECT *
FROM Table2
WHERE ID IN (SELECT ID FROM Table1)
Upvotes: 1
Reputation: 25938
You probably want to JOIN
tables:
SELECT table2.* FROM table2 JOIN table1 ON (table2.tb2_id=table1.id)
Upvotes: 3
Reputation: 13571
You need either a join or a subquery.
Select t2.*
from table2 t2
Inner join table1 t1
On t2.tbl2_id = t1.id
Or
Select t2.*
from table2 t2
where tbl2_id in ( select id from table1 )
Upvotes: 1