I have two tables which I am left joining together.
SELECT Col3, tab1.Col1, tab1.Col2 FROM
(SELECT Col1,Col2
FROM Table1
GROUP BY Col1,Col2) tab1
LEFT JOIN
(SELECT Col3, Col1, Col2
FROM Table2
GROUP BY Col3, Col1, Col2) tab2
ON tab2.Col2 = tab1.Col2 AND tab2.Col1 = tab1.Col1
At the moment for the rows in Table1 which do not exist in Table2 I return a row where Col3 is Null. As I am grouping data based on Col3, it would be good if I could somehow get the value of Col3 instead of Null…..
Is this possible??
So I am trying to return every possible combination of col1 and col2, per value of col3. The problem is when col3 does not contain a particular combination of col1,col2 I am getting nulls for col3…
Assuming Col3 is some kind of category, and is a primary key of a
categorytable, you might do this:Cross join produces Cartesian product of tables involved, retrieving Col3 which might not be found in Table2.