0

Given two columns, t1 with distinct values, but a superset of t2, how is it possible to operate over t1 to subtract the elements of t2 of t1? I utilize MySQL 5.7

CREATE TABLE IF NOT EXISTS t1 (
   id_ INTEGER  NOT NULL,
   value1 INT NOT NULL
INSERT INTO t1 (id_, value1) VALUES
(1),
(2),
(3),
(4),
(5),
(6),
(7),
(8)

CREATE TABLE IF NOT EXISTS t1 (
   id_ INTEGER  NOT NULL,
   value1 INT NOT NULL
INSERT INTO t2 (id_, value2) VALUES
(1),
(2),
(3),
(4)
2
  • @BrunoHenriquePeixoto: The EXCEPT or MINUS operation would seem perfect for this, as suggested by the tags just edited in. But since MySQL 5.7 supports neither, an anti-join is probably the only option for you, and what you did was one of the ways of implementing an anti-join. (The other two I know of involve NOT EXISTS and NOT IN, but the LEFT JOIN + WHERE IS NULL option that you used is used most often in MySQL.) So it looks like you managed this on your own, well done.
    – Andriy M
    May 28 at 9:26
  • Ok, I am satisfied with the answer. Thank you. May 28 at 13:04