Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 combine 2 columns from different table

Author  Topic 

jimmy2090
Starting Member

26 Posts

Posted - 2015-04-29 : 22:30:39
hi all, i want to combine 2 columns from different table.

let said my table1:
id: A1 customername: WesternDigital
id: A2 customername: Sony
id: A3 customername: Samsung

my table2 :
id: A1 customername: Rose
id: A3 customername: John

my output is like that:
customername
WesternDigital, Rose
Sony
Samsung, John

my sql as below:

select table1.customername + table2.customername as customername
from table1
inner join table2 on table1.id = table2.id


how to make the table1 sony appear also even it does not exist in table2?

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2015-04-30 : 01:40:45
@jimmy2090 - You'll need to use a LEFT JOIN as opposed to an INNER JOIN. The LEFT JOIN will include rows from left table plus all joins made with right table.

Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page
   

- Advertisement -