Trouble excluding matched values in SQL

32 views Asked by At

I am trying to bring up potential name matches with keywords and then transfer the IDs from one table to the other. My issue is arising where I cannot filter out results from the ID table that have already been matched (and therefore have a matching ID in the initial table). I have tried this:

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%";

As well as attempting to mimic a full outer join:

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%"

NOTE: "%chic%" is just any keyword/string

0

There are 0 answers