【发布时间】:2013-05-26 12:36:36
【问题描述】:
我有三个表 table1、table2、table3。 table1 有 a、b 列。表 2 有 c、b、d 列。 Table3 有 d、e 列
Table 1 Table 2 Table 3
a b c, b, d d e
我需要匹配 b 上的 table1、table2 和 d 上的 table2 和 table3。我需要在表 1 的“a”列中显示数据,并且如果由于 table2 和 table3 中的匹配而存在行,那么我需要在表 3 中显示“e”列以及“a”列。如果 table2 和 table 3 之间的匹配中不存在任何行,我可以显示 null。
如有任何澄清或数据,请告诉我。我正在使用 sqlite3,但存在子句的工作方式就像在 sql 中一样。
我尝试过,但无法为此编写适当的查询。
select a, e from table1 t1 join tablet2 t2 on t1.b = t2.b (and if exists?)
【问题讨论】:
-
codinghorror.com/blog/2007/10/… 将帮助您了解联接