Unable to fetch all the rows while performing full outer join in snowflake SQL

757 views Asked by At

I have two tables. First table is

Category       Date        Sales_1
Chocs          2020-10-10  2091847.8100
Biscuits       2020-10-10  1.6000
Rice           2020-10-10  597003.4900
Sugar          2020-10-10  1533084.3100
Chips          2020-10-10  3.5000
Sweet          2020-10-10  3.0000

2nd table is

Category       Date        Sales_2
Chocs          2020-10-10  2091847.8100
Biscuits       2020-10-10  1.6000
Rice           2020-10-10  597003.4900
Sugar          2020-10-10  1533084.3100
Spices         2020-10-10  90748.89
Chips          2020-10-10  3.5000
Sweet          2020-10-10  3.0000

If i do full outer join on category from table 1 and table 2 on category. i.e.

   Category       Date            Sales_1         Sales_2
   Chocs          2020-10-10      2091847.8100    NULL
   Biscuits       2020-10-10      1.6000          NULL
   Rice           2020-10-10      597003.4900     NULL
   Sugar          2020-10-10      1533084.3100    NULL
   NULL           NULL            NULL            90748.89
   Chips          2020-10-10      3.5000          NULL
   Sweet          2020-10-10      3.0000          NULL
   

It's not including below value in the about output

Category       Date        Sales_1   Sales_2
NULL           NULL        NULL      90748.89

Expected output must be, it should return all the rows. I tried the below snowflake SQL query

select coalesce(table_1.category,table2.category) cat,
       coalesce(table_1.date,table2.date) dt,
       coalesce(table_1.sales,table2.sales) sales
from table_1 
full outer join table_2 on table_1.category = table_2.category

Can anyone help me with this?

1

There are 1 answers

0
Mark On

The SQL query is below. It's the same as above, there was a mistake in my data.

select coalesce(table_1.category,table2.category) cat,
       coalesce(table_1.date,table2.date) dt,
       coalesce(table_1.sales,table2.sales) sales
from table_1 
full outer join table_2 on table_1.category = table_2.category