mysql - 3 tables and 2 independent JOINs with CONCAT expressions -


i have following 3 tables ids

table: users

user | name   1  | joe   2  | john 

table: user_id1

user | id1   1  |   2   1  |   3   2  |   5 

table: user_id2

user | id2   1  |   3   1  |   4 

i following result each user

name | ids 1 | ids 2  joe | 2,3   | 3,4  john| 5     | null 

i use query:

select   user.name,   group_concat(user_id1.id1) "ids1",   group_concat(user_id2.id2) "ids2"  users  left join user_id1   on user_id1.user=users.user  left join user_id2   on user_id2.user=users.user 

but result:

name | ids1    | ids2 joe  | 2,2,3,3 | 3,4,3,4 john | 5       | null 

what wrong? help

using distinct should solve it

select   user.name,   group_concat(distinct user_id1.id1) "ids1",   group_concat(distinct user_id2.id2) "ids2"  users  left join user_id1   on user_id1.user=users.user  left join user_id2   on user_id2.user=users.user 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

ios - Possible to get UIButton sizeThatFits to work? -