Sample for post 9421369

0

Please login or register to vote for this query.

(click on this box to dismiss)

Physics

Q&A for active researchers, academics and students of physics

WITH TableA as 
(
SELECT 'A' as master , 1 ColA
UNION SELECT 'A' , 2
UNION SELECT 'B' , 1
UNION SELECT 'B' , 2),
TableB as (
SELECT 'A' as master , 1 ColB
UNION SELECT 'A' , 3
UNION SELECT 'B' , 1
UNION SELECT 'B' , 2
UNION SELECT 'C' , 1)

SELECT 
  masters.master AS master,
  TableA.ColA AS ColA,
  TableB.ColB AS ColB
FROM
    (
      SELECT master FROM TableA
      UNION
      SELECT master FROM TableB
    ) AS masters
    LEFT JOIN TableA ON masters.master=TableA.master
    LEFT JOIN TableB ON masters.master=TableB.master
ORDER BY
    master, ColA, ColB

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results