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)
 Get only one row from table

Author  Topic 

Chengli
Starting Member

10 Posts

Posted - 2008-07-16 : 01:10:47
Table:
A - AID, ANAME
B - BID, BNAME
C - AID, BID, aStatus

Sample Data:
Table A
AID ANAME
A1 A1
A2 A2

Table B
BID BNAME
B1 B1
B2 B2

Table C
AID BID sSatus
A1 B1 Yes
A2 None Yes

How can i get the result is like following

AName BNAME aStatus
A1 B1 Yes
A2 NONE Yes


and i try inner join, left & right outer join already but the resule give me is not i want . Only one row record is display

AName BNAME aStatus
A1 B1 Yes


Following code is i try

SELECT B.BNAME, A.ANAME, C.status
FROM A INNER JOIN
C ON A.Aid = C.AID CROSS JOIN
B

where A.Aid=C.Aid and B.BId=c.BId

thanks for help

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-16 : 01:26:04
[code]SELECT a.ANAME, b.BNAME, c.sStatus
FROM TableC c
left JOIN TableA a ON c.AID = a.AID
left JOIN TableB b ON c.BID = b.BID[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Chengli
Starting Member

10 Posts

Posted - 2008-07-16 : 02:12:18
Thanks for ur help ... the solution u gave is work ...
Go to Top of Page
   

- Advertisement -