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 2000 Forums
 SQL Server Development (2000)
 joining 2 columns in A to 1 in B

Author  Topic 

portrman
Starting Member

24 Posts

Posted - 2003-07-31 : 19:38:00
So I have table A with say uid, owner_id, creator_id
table B has uid, username

I am currently doing a join like
SELECT a.uid, a.owner_id, b.username AS owner_str, a.creator_id
FROM a
LEFT OUTER JOIN b ON a.uid = b.uid

But now I've added the a.creator_id and need to join again with b to get the username for that column. How would I do that?

I would like to add something such as
b.username AS creator_str
but that always returns the same as owner_str

Thanks

rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2003-07-31 : 19:50:15
hi, do you mean this?

SELECT a.uid, a.owner_id, b.username AS owner_str, c.username as creator_str
FROM a
LEFT OUTER JOIN b ON a.uid = b.uid
LEFT OUTER JOIN b c ON a.creator_id = b.uid


--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"
Go to Top of Page

portrman
Starting Member

24 Posts

Posted - 2003-08-01 : 12:49:35
ah perfect, I forgot you could using aliasing in join statments.

Thanks a million.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-08-01 : 12:54:21
You can use aliasing wherever you want and not just in join statements. You can alias tables, views, columns, etc...

SELECT Column1 AS Alias1, Column2 AS Alias2
FROM Table1 a

Tara
Go to Top of Page
   

- Advertisement -