Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SELECT'ing certain fields using JOIN queries 1

Status
Not open for further replies.

y2k1981

Programmer
Aug 2, 2002
773
IE
I don't know how to explain this very well, but how do I select certain fields from different tables using a join query? For example:

Code:
SELECT * FROM users LEFT JOIN usersingroups USING (userid) LEFT JOIN groups USING (groupid) WHERE groups.group_type = 'type1'

But suppose, instead of everything, I just want the following fields:
users.userid
users.name
groups.groupid
groups.groupname

If it were just the first 2 fields, I could say users.userid, users.name instead of *, but I don't know how to do it for the second table. can anybody help me at all?
 
so you're saying use SELECT users.userid, users.name, groups.groupid, groups.groupname FROM users ... - I've tried that but it doesn't work. anyway, how could it - SELECT groups.gropuid FROM users wouldn't work would it?
 
what does "I've tried that but it doesn't work" mean? query ran but produced no results? query ran but produced wrong results? query crashed the server? query didn't run because of syntax error? what was the error?

:)

anyway, how could it work? because you are allowed to select any columns from any table in the FROM clause

note that the FROM clause includes all tables joined together

rudy | r937.com | Ask the Expert | Premium SQL Articles
SQL for Database-Driven Web Sites (course starts January 9 2005)
 
>> what does "I've tried that but it doesn't work" mean? query ran but produced no results? query ran but produced wrong results? query crashed the server? query didn't run because of syntax error? what was the error?
[lol]

Sorry, you're right it does work. All the times I tried this before, I was 100% sure it generated an error [ponder]

Sorry again, and star for your patience !!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top