JOIN returns only a single result
I have to query a given table. I can't change the table structure. It's
basically like this:
user
-- ---------- ----
id address_id name
address
-- ---
id zip
language
-- ----
id lang
Where the id of entries in language is the same as the user's id. Its
primary key is based on id and lang. address_id on user can be null.
Now I want to get everything with a single query. I've tried:
SELECT
p.name,
l.lang,
a.zip
FROM user p
JOIN language l ON p.id = l.id
LEFT JOIN address a ON p.address_id = a.id
WHERE p.id = :id
LIMIT 1
Which actually works except for one thing: It only returns the first
language that is connected to the user. How can I retrieve all languages?
No comments:
Post a Comment