I have these 2 tables:
table1:
id | name
---------
1 | john
2 | jack
table2:
id | profile_id | institution
-----------------------------
1 | 1 | SFU
2 | 1 | UBC
3 | 2 | BU
4 | 2 | USC
5 | 2 | SFU
If I want to get all the information about a user using his userid, I can simply join them using this:
select a.id, a.name, b.institution from table1 a, table2 b
where a.id = USER_ID and a.id = b.profile_id
which for USER_ID = 1 returns:
id | name | institution
-----------------------
1 | john | SFU
1 | john | UBC
What I need is actually 1 unique row instead of multiple rows. Is it in any way possible to get something like this? (I haven't seen something to do it but am not sure)
id | name | institution
-----------------------
1 | john | [SFU, UBC]
Best Answer
You can use the GROUP_CONCAT function
or with your original query
Give it a Try !!!