使用此查询,我从两个表中获取数据。不幸的是,如果“Table2”没有记录,即使是“表1”也没有提取。即使“Table2”没有相应的数据,我怎样才能得到“表1”的数据?
String tabella_conti = "SELECT a._id, " +
"a.CAMPO1, " +
"a.CAMPO2, " +
"a.CAMPO3, " +
"SUM(b.ZAMPO1) - SUM(b.ZAMPO2), " +
"b.ZAMPO3 " +
"FROM Table1 a LEFT JOIN MyTable b ON (a.CAMPO1 = ZAMPO3) WHERE "+MyTable.DATA+ " <=? GROUP BY a.CAMPO1";
答案 0 :(得分:2)
通过将AND替换为AND
,使其成为join子句的一部分SELECT (...)
FROM Table1 a
LEFT JOIN MyTable b
ON a.CAMPO1 = ZAMPO3
AND (...)
GROUP BY (...)
这可确保不会排除table1中的任何行。