Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL Joins Question 1

Status
Not open for further replies.

pseudosig

Technical User
Mar 3, 2004
4
US
Suppose you have the following tables:

Code:
t1

 _c1_c2_
| a | 1 |
| a | 9 |
| a | 4 |



t2
 _c1____c2__
| a | alpha |
| b | beta  |

Is there a way to query the two tables (perhaps a weird join) that would return the following?:

Code:
 _t2.c1___t2.c2___(something here)_
|   a   | alpha |     1,9,4        |

Basically, a join-like query that would bundle multiple data, like that in t1.c2, into a single row?

Thanks in advance...
 
yes, you need to use GROUP_CONCAT

Code:
select t2.c1, t2.c2, group_concat(t1.c2) as mygroupalias
from t1 join t2
on t1.c1=t2.c2
group by
t2.c1,
t2.c2
 
That's cool. I wasn't aware of GROUP_CONCAT. Worth a star.

Andrew
Hampshire, UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top