4

I wanted to have a full outer join in memsql. Something like

SELECT *
FROM A FULL OUTER JOIN B
ON A.id  = B.id

Is it possible ?

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
Vivek Aditya
  • 1,145
  • 17
  • 46

1 Answers1

4

It appears that MemSQL does not have a FULL OUTER JOIN syntax. However, you should be able to simulate a full outer join in MemSQL using a combination of LEFT and RIGHT OUTER JOIN operations:

SELECT * FROM A
LEFT OUTER JOIN B ON A.id = B.id
UNION ALL
SELECT * FROM A
RIGHT OUTER JOIN B on A.id = B.id
WHERE ISNULL(A.id)

                                                enter image description here

The first SELECT covers the orange area, namely matching records between A and B along with records in A which do not match to anything in B. The second query obtains only records in B which do not match to anything in A. Using UNION ALL instead of UNION ensures that duplicates are not removed.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360