When I do an outer join on mssql, the columns I join on do not combine.
Here is my code:
select top 10 * from customer_behaviour_1P2014 full outer join
customer_behaviour_2P2014 on customer_behaviour_1P2014.customer_identifier = customer_behaviour_2P2014.customer_identifier full outer join
customer_behaviour_3P2014 on customer_behaviour_2P2014.customer_identifier = customer_behaviour_3P2014.customer_identifier
This returns 3 columns labeled customer_identifier, instead of 1.
What am I doing wrong?
If it makes any difference I made customer identifier a index in each table.
You are selecting all columns from all 3 tables, and each table has a
customer_identifiercolumn (deduced from theONclauses).Each
customer_identifiercolumn in the result is from a different table. The values will be the same when matched orNULLwhen no row matches.Specify an explicit column list instead of
*to avoid repeating the values. Instead of the 3 separatecustomer_identifiercolumns, use aCOALESCEfunction to return the first non-NULL value: