简单地说:
SELECT
table1.field1,
table2.field2,
table3.field_WHAT
FROM
table1,
table2,
table3
WHERE
table1.field1 = 'HELP'
and table2.field1 = table1.field1
and table3.field2 = table2.field2
我仍然想要table1&的所有匹配行table2,即使找不到table3.field2的匹配记录...而理想情况如果没有匹配,table3.field_WHAT
将返回""
或NULL
。
答案 0 :(得分:0)
试试这个:
SELECT
table1.field1,
table2.field2,
table3.field_WHAT
FROM
table1
INNER JOIN
table2 ON table1.field1 = table2.field1
LEFT OUTER JOIN
table3 ON table3.field2 = table2.field2
WHERE
table1.field1 = 'HELP'
答案 1 :(得分:0)
这是outer join
的经典案例:
SELECT
table1.field1,
table2.field2,
table3.field_WHAT
FROM
table1,
JOIN
table2 ON table2.field1 = table1.field1
OUTER JOIN
table3 ON table3.field2 = table2.field2
WHERE
table1.field1 = 'HELP'