0

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?

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much, Gordon.
2

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'

1 Comment

Thank you, Asromi.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.