Skip to content
Advertisement

Select in a select from another table [closed]

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:

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

Advertisement

Answer

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

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement