Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Select in a select from another table

I need to make a query to another table and add the result to the current one as a new record if there is no record with an id in it, but if the current table has a value with such an id then add the value.

table 1:

id name date
1 alex 2022-01-01
2 tom 2022-01-01

table 2:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

id name pass
1 alex 111
3 mitch 222

expected result:

id name date value
1 alex 2022-01-01 111
2 tom 2022-01-01
3 mitch 222

>Solution :

Its a merge results for both the tables so you query will be

select * from table1 full outer join table2 on table1.(some column name) = table2.(some column name)

here some column name represents you id in table1 and table2 respectively.
so your query will be

select * from table1 full outer join table2 on table1.id = table2.id

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading