无法排除SQL中的匹配值

时间:2015-06-09 17:11:08

标签: sql sequelpro

我正在尝试使用关键字显示潜在的名称匹配,然后将ID从一个表传输到另一个表。我的问题出现在我无法过滤掉已经匹配的ID表的结果(因此在初始表中具有匹配的ID)。我试过这个:

SELECT m.sname, u.fname, u.UUID, m.UUID
FROM pl_MDR m
LEFT JOIN pl_UUID u     ON m.UUID=u.UUID
WHERE m.UUID is null
      AND m.sname LIKE "%chic%"
      AND u.fname LIKE "%chic%";

除了尝试模仿完整的外部联接:

SELECT m.sname, u.fname, u.city, u.UUID, m.UUID
FROM pl_UUID u
LEFT JOIN pl_MDR m     ON u.UUID != m.UUID
WHERE m.UUID is null
      AND m.sname LIKE "%chic%"
      AND u.fname LIKE "%chic%"
UNION ALL
SELECT m.sname, u.fname, u.city, u.UUID, m.UUID
FROM pl_UUID u
RIGHT JOIN pl_MDR m     ON u.UUID != m.UUID
WHERE m.UUID is null
      AND m.sname LIKE "%chic%"
      AND u.fname LIKE "%chic%"

注意:"%chic%"只是任何关键字/字符串

0 个答案:

没有答案