Reputation: 93
I need to join table1 and table2. I don't know the name of table2, but it is a record in table 1. so I'm trying this:
SELECT table2.*
from table1 t
JOIN (
SELECT tname from table1 t1 WHERE t.id = t1.id
) as table2 ON table2.ref = t.ref
WHERE ...
but it is not working. Any ideas? thanks
my error is: "Unknown column 't.id' in 'where clause'"
Upvotes: 1
Views: 1306
Reputation: 77866
You can modify your query to be like below. Give it a try
SELECT t.*
from table1 t
JOIN (
SELECT id, tname from table1
WHERE some_condition
) table2 on t.id = table2.id
WHERE ...
Upvotes: 2