Reputation: 3
I have two tables:
[customer]
id
name
[customer_photo]
id
customer_id
photo
I want to select all customers and their photos.
This query is doing it, but getting only users who have at least one photo:
SELECT customer.id, name, GROUP_CONCAT(cp.photo) as photos
FROM customer
JOIN customer_photo cp ON cp.customer_id = customer.id
GROUP BY customer.id
I want to get all users, even if they don't have a photo.
Upvotes: 0
Views: 24
Reputation: 81930
Just by adding the LEFT join
SELECT customer.id, name, GROUP_CONCAT(cp.photo) as photos
FROM customer
LEFT JOIN customer_photo cp ON cp.customer_id = customer.id
GROUP BY customer.id
Upvotes: 1