Reputation: 9073
First select query
Table 1:
ID Value
131 ABC
120 DEF
Second select query
Table 2:
ID
120
131
I want to write a single query which will fetch me combining two tables (the required output)
ID Value
120 DEF
131 ABC
Note: if there is no entry in Table2, return the data from Table1 else combine and return the result.
Any thoughts? Thanks.
Upvotes: 0
Views: 1076
Reputation: 10598
something like that:
SELECT *
FROM Table1 t1
LEFT OUTER JOIN Table2 t2 ON t1.ID = t2.ID
Upvotes: 0
Reputation: 4311
SELECT *
FROM table1 LEFT JOIN table2
ON table1.ID = table2.ID
if it can't find the matching record in table2 it will fill table2 columns in the result set with null
Upvotes: 2