hello ! i need to join twice two mysql tables and i don't know how.What i want to do looks something like this:
SELECT *
FROM emails
left JOIN personen ON emails.id_person = personen.id
left JOIN themen ON emails.id_thema = themen.id
left join login on emails.id_berater=login.id
left join login on emails.id_supervisor=login.id
except that i cannot join with login.id twice.What would the solution be?
how can i join twice two mysql tables...
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
you "can't" join them because of a table referencing ambiguity:
Code: Select all
SELECT *
FROM emails
left JOIN personen ON emails.id_person = personen.id
left JOIN themen ON emails.id_thema = themen.id
left join login a on emails.id_berater=a.id
left join login b on emails.id_supervisor=b.idhere is the solution i found:
Code: Select all
CREATE temporary TABLE `login2`(....)
INSERT INTO login2 SELECT ....FROM login
SELECT * FROM emails
LEFT JOIN personen ON emails.id_person = personen.id
LEFT JOIN themen ON emails.id_thema = themen.id
LEFT JOIN login ON emails.id_berater = login.id
LEFT JOIN login2 ON emails.id_supervisor = login2.id