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.
| Author |
Topic |
|
bpsintl
Posting Yak Master
132 Posts |
Posted - 2009-08-21 : 04:57:17
|
| Hi, I have 3 tables, users, venues and services.A user can either have a venue associated to him, a service associated to him or both.Basically I need a query that will pull the user, and either the venues record or service record or both that are associated with him.The users table pk is user_id. The venue and services tables have a fk of userid.User tableUser_idusernameVenues tablevenue_idvenue_nameuseridservices tableservice_idservice_nameuserid(other fields left out that are not needed for this query)Hope that makes sense! |
|
|
YellowBug
Aged Yak Warrior
616 Posts |
Posted - 2009-08-21 : 06:53:11
|
| Think you need the LEFT JOIN, like this:SELECT *FROM UserTable ULEFT JOIN VenuesTable V ON U.User_id = V.useridLEFT JOIN ServicsTable S ON U.User_id = S.useridIt's usually a good idea to keep the field names the same in different tables, i.e. use User_id always, instead of User_id and userid. |
 |
|
|
bpsintl
Posting Yak Master
132 Posts |
Posted - 2009-08-21 : 08:23:28
|
| Great, thanks for that. I didn't think of left joins! |
 |
|
|
|
|
|