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 2005 Forums
 Transact-SQL (2005)
 SQL Query Help !!!

Author  Topic 

tiffiny
Starting Member

7 Posts

Posted - 2007-08-09 : 05:30:53
tableA
ID Name
A1 A
A2 B
A3 C

tableB
ID Main Name Parent
B1 A1 aaa
B2 A1 bbb B1
B3 A1 ccc

I wish to produce result below without using union,is this posible?
ID Name Name Name
A1 A aaa
A1 A aaa bbb
A1 A ccc

I try to use the query below
Select a.ID,a.Name,b.Name,b2.Name from tableA a
INNER JOIN tableB b ON a.ID = b.Main
LEFT OUTER JOIN
tableB AS b2 ON b.ID = b2.Parent

but the result
ID Name Name Name
A1 A aaa bbb
A1 A ccc

sutysw
Starting Member

3 Posts

Posted - 2007-08-09 : 06:05:24
SELECT a.ID, a.Name1, b.Name, b2.Name AS NameParent
FROM TableA AS a INNER JOIN
TableB AS b ON a.ID = b.Main LEFT OUTER JOIN
TableB AS b2 ON b.Parent = b2.ID
Go to Top of Page

tiffiny
Starting Member

7 Posts

Posted - 2007-08-09 : 06:13:49
Thanks for your help!
Go to Top of Page
   

- Advertisement -