Reputation: 4301
I want to query two databases. I want all fields from db1 and one more field from db2.
The command is like this:
select name from db2 where id in (select id from db1 where date > '2018-1-1')
Then I need to query db1 for all the fields again.
select * from db1 date > '2018-1-1'
How to combine these two queries?
Upvotes: 0
Views: 47
Reputation: 199
Try This One
select AA.*, BB.Name
from db1 AA
Left Join db2 BB On BB.id = AA.id
Where AA.date > '2018-1-1'
Upvotes: 2
Reputation: 1270713
Something like this:
select db2.name, db1.*
from db1 join
db2
on db1.id = db2.id
where db1.date > '2018-01-01';
Depending on the structure of your tables this might be exactly equivalent. However, based on your question, I'm guessing that this is what you really want to accomplish.
Upvotes: 3