Joining the same table twice?
Date: 11/18/05
(MySQL Communtiy) Keywords: no keywords
SOLVED!
I have a table that has two fields. Each field contains a project number, which is the primary key of the project table. I'd like to be able to run a query where I join this table to the main table so that I can get the project titles (another field) for both of the two numbers. I tried this:
SELECT pn_project_rel_proj.relid, pn_project_rel_proj.proj1, pn_project_rel_proj.proj2, pn_project_rel_proj.relation, pn_project_projects.projid, pn_project_projects.title
FROM pn_project_rel_proj
LEFT JOIN pn_project_projects
ON proj1 = projid
LEFT JOIN pn_project_projects
ON proj2=projid
WHERE proj1 = '2' || proj2 = '2'
The error message tells me that it won't work because the "pn_project_projects" isn't unique.
How can I get this to work?
Source: http://www.livejournal.com/community/mysql/73399.html