我有两个表:table1
和 table2
。在这两个表中,msg_id
很常见。
我编写了以下查询:
select alert.MSG_ID, alert.ACTION,
alert.ALERT_ID, alert.CONTACT_DETAIL,
alert.TRXREFNUMBER, alert.TARGET_SYSTEM,
log.MSG_ID, log.ACTION, log.ERR_CODE, log.CONTACT_DETAIL
from bnea.table1 alert,
bnea.table2 log
where not exists (select a.MSG_ID
from bnea.table2
where alert.MSG_ID = log.MSG_ID);
但是它不起作用。当我执行上述查询时,它会交叉连接所有记录。
有人有这样或类似查询的经验吗?
最佳答案
您可以使用这种格式的查询来获取没有任何重复结果的输出。
SELECT DISTINCT column1, column2,.....columnN
FROM table_name
WHERE [condition]
关于mysql - SQL查询在两个表中查找非重复值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33951489/