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
 Simple sql query question

Author  Topic 

wab0111
Starting Member

2 Posts

Posted - 2012-02-29 : 05:04:37
I am somewhat new to SQL queries. Limited exposure over the years but am working on learning more. I created the query below. Instead of presenting GroupID in the results, I would like to return the corresponding Groupname from the Groups table. How do I do that with this query? Username and Fullname are from the table Users. GroupID is from GroupMembers. GroupID and Groupname are both in the table Groups. Thanks.

select Username, FullName, GroupID from Users
join GroupMembers
on Users.UserID=GroupMembers.UserID order by Username

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-02-29 : 05:24:39
select u.Username, u.FullName, g.Groupname
from Users u
join GroupMembers gm on u.UserID=gm.UserID
join Groups g on g.GroupID=gm.GroupID
order by u.Username


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -