我有以下数据库可以在Android 3.0平板电脑应用程序中使用它。
我想选择EReportDefect
上不存在的每个缺陷。正如您所见,EReportDefect.defectId
可能为空。
此选择返回0行。但是有些缺陷不在EReportDefect
表格上。
SELECT
Defect.defectId,
Defect.description
FROM
Defect
WHERE
qapId = ? AND
defectId NOT IN
(SELECT defectId FROM EReportDefect WHERE eReportId = ?);
我做错了什么?
答案 0 :(得分:3)
您可以使用defectID
,
LEFT JOIN
列上的两个表格
SELECT a.*
FROM Defect a
LEFT JOIN EReportDefect b
ON a.defectID = b.defectID
WHERE b.defectID IS NULL
如果b.defectID
上没有匹配项,则 NULL
会有a.defectID
个值。
更新1
SELECT a.*
FROM Defect a
LEFT JOIN EReportDefect b
ON a.defectID = b.defectID
WHERE b.defectID IS NULL AND
a.qapID = ?
-- AND b.ReportID = ?
答案 1 :(得分:0)
这就是我的作品:
SELECT
Defect.defectId,
Defect.description
FROM
Defect
WHERE
qapId = ? AND
defectId NOT IN
(SELECT
defectId
FROM
EReportDefect
WHERE eReportId = ? AND defectId IS NOT NULL);
答案 2 :(得分:-1)
也许我错过了一些东西,但对我来说,似乎你删除了“qapId =?AND”和“WHERE eReportId =?”它应该只返回EReportDefect表中没有条目的结果
SELECT
Defect.defectId,
Defect.description
FROM
Defect
WHERE
defectId NOT IN
(SELECT defectId FROM EReportDefect);