Skip to content
Advertisement

UNION based on common column

I have 2 tables:

enter image description here

And I want to create UNION query, based on the common rows of EAN. Like, in the end, I want my table to look like: enter image description here

Any helps would be really appreciated!

Thanks in advance!

Advertisement

Answer

Try this ?

SELECT
  a.ean,
  a.price,
  a.company,
  a.lowestPrice
FROM
  Table1 a
UNION
SELECT
  b.ean,
  b.price,
  b.company,
  NULL AS lowestPrice
FROM
  Table2 b 
  INNER JOIN Table1 c ON c.ean = b.ean
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement