Chan
Chan

Reputation: 4301

Combining two SQL query commands

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

Answers (2)

Asromi rOmi
Asromi rOmi

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

Gordon Linoff
Gordon Linoff

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

Related Questions