-
Multi-table Query Help
The people over at webdeveloper.com haven't been able to solve this. I am using MySQL. Tables are as follows:
Users
id - PK
group_id
username
email
Meta
id - PK
users_id - FK
fname
lname
company
Groups
id - PK
name
Projects
id - PK
proj_name
and the following intermediate table for the many to many relationships:
users_projects
users_id - FK
projects_id - FK
Trying to select the information of the users assigned to a specific person's projects.
Looking to select user.id, user.email, meta.fname, meta.lname, projects.proj_name for a specific user_id's projects.
For example, if I am user_id #1, I would like to find all of my projects, and then list all the other users assigned to those same projects.
The closest I got was:
SELECT users.id, users.email, projects.proj_name
FROM users, users_projects
JOIN projects ON projects.id = users_projects.projects_id
WHERE users_projects.users_id = users.id
which lists every user assigned to each project. (users can be assigned to more than one project). However, when I try to make it work by substituting a specific user # for users.id, it shows all that users are assigned to that user's projects, which is wrong.
Any help pointing me in the right direction would be appreciated.
Terry
-
Someone over at webdeveloper.com solved this for me.
Terry
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|