We have a scenario where we want all the data which satisfies inner join also one more record even if it fails join condition. To include that one unmatched record we have primary key value, we can not apply Left join coz it include all the unmatched records from left table but we are interested in only 1.
ex. We have a primary key value Id = 3.
Table 1:
Table1_ID Table1_Name
1 Test
2 Test_1
3 Test_2
Table 2:
Table2_ID Table2_Name
1 Test
Expected result:
ID Name
1 Test
3 Test3
2条答案
按热度按时间lf3rwulv1#
You could try to use
LEFT JOIN
, then filter un-matched records inWHERE
conditionsSee demo here
bvjxkvbb2#
You can use a union to treat two queries as one.