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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 compress multiple row into single row

Author  Topic 

rhinestone89
Starting Member

1 Post

Posted - 2012-03-02 : 23:19:12
Good Day everyone. I'm trying to achieve something I've never tried before so please help me. I have three tables which are shown below

Table 1
id sex
1 m
2 f
3 m

Table 2
id beg_balance
1 12
3 3



Table 3
id beg_balance
1 33
2 4

I want to produce something like this

id sex beg_balance_from_table_2 beg_balance_from_table_3
1 m 12 33
2 f 4
3 m 4

I've tried a lot of variations but nothing seems to work. Please help me on this. Thank you


visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-02 : 23:42:39
as simple as this

SELECT t1.id,t1.sex,t2.beg_balance as beg_balance_t2,t3.beg_balance as beg_balance_t3
FROM table1 t1
LEFT JOIN table2 t2
ON t2.id = t1.id
LEFT JOIN table3 t3
ON t3.id= t1.id


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -