-1

Suppose we have a list A and an identical list B except that B has one element removed. Find that missing element.

I would think that one possible approach would be the following:

 select a.element from
 a left join b
 on a.element = b.element
 where b.element is null

Would that be correct?

Damien
  • 382
  • 3
  • 8
  • 17
  • 1
    That is a fine solution. Often `not exists` or `not in` would be used. But this is 100% valid and in some databases has the best performance. – Gordon Linoff Aug 15 '17 at 15:46
  • Other approaches involve `minus` or `except` `select a.element from A MINUS Select B.element from B` but what you have is fine. – xQbert Aug 15 '17 at 15:49
  • Possible duplicate of [SQL - find records from one table which don't exist in another](https://stackoverflow.com/questions/367863/sql-find-records-from-one-table-which-dont-exist-in-another) – Tab Alleman Aug 15 '17 at 18:15

1 Answers1

0

You can use a WHERE clause to select a statement where a.element is not present in b.element, like the example below:

SELECT a.element
FROM a
WHERE a.element NOT IN (SELECT b.element FROM b)