Reputation: 507
I have two tables
users table
id name
1 john
2 reaper
users_bid table
id user_id amount
1 1 50
2 1 100
3 2 80
4 1 120
Now i want a query which will give the below result
id user_id amount
1 1 50,100,120
2 2 80
Upvotes: 0
Views: 63
Reputation: 11205
You want GROUP_CONCAT()
select T1.id, T2.user_id, group_concat(T2.amount order by T2.amount separator ', ') as amount
from users T1
inner join users_bid T2
on T2.user_id = T1.id
group by T1.id, T2.user_id
Upvotes: 2
Reputation: 90
SELECT users.id, users_bid.user_id, users_bid.group_concat(amount) AS amount
FROM users
JOIN users_bid ON users_bid.user_id = users.id
GROUP BY users.id
Upvotes: 1