我有这个查询:
SELECT r.id, r.RowID, r.RAMQ, r.Type, r.Description, r.Deleted
FROM reminders r, patientdetails
WHERE (patientdetails.RAMQ = r.RAMQ OR r.RAMQ='none' )
AND r.Deleted != '1'
当此Query运行时,它会复制RAMQ为none的结果。这是为什么?
答案 0 :(得分:2)
我猜你只想要一张桌子的数据。所以,不要使用连接(这是你在那里的隐藏连接),而是使用EXISTS
子查询:
SELECT r.id, r.RowID, r.RAMQ, r.Type, r.Description, r.Deleted
FROM reminders AS r
WHERE ( r.RAMQ = 'none'
OR EXISTS
( SELECT *
FROM patientdetails AS p
WHERE p.RAMQ = r.RAMQ
)
)
AND r.Deleted <> '1' ;