如果满足条件,SQL 连接 2 个表

问题描述 投票:0回答:1
Table1
column1 | column2 | column 3 |
abc     | def     |  ghi     |
abc1    | def1    |  ghi1    |
abc2    | def2    |  ghi2    |    

Table2
column11 | column22 | column 33 |
abc1     | def2     |  ghi3     |
abc11    | def12    |  ghi13    |
abc22    | def22    |  ghi23    |     

我需要一个 SQL 查询,例如如果 table1.column1 = abc,则从 table2 选择列 11,否则为 null

我尝试使用连接和并集,但没有任何效果

sql join union
1个回答
0
投票

当我迷路时,我经常查看此链接

我会尝试:

SELECT table2.column11, table1.column1

FROM table1

LEFT JOIN table2 ON table1.column1 = 'abc'
;
© www.soinside.com 2019 - 2024. All rights reserved.