>ssp-cdr<
01-27-2010, 06:38 PM
I have a question concerning using a subquery in a SELECT statement. The problem I am having occures because a subquery is only allowed to return one row, but my subquery may return several rows.
In my database there is a user table, a usergroup table and, since a user can be in multiple usergroups, a user-usergroup table to link the two.
This is they kind of query I want to runSELECT
username,
(SELECT usergroupid FROM `user-usergroup` WHERE userid = 150) AS usergroupids
FROM user WHERE userid = 150
What I would like this query to return is the username and a comma separated list of usergroupids.
Because a subquery is only allowed to return one row, I am wondering if there is some way to compact multiple rows into a string (similar to what can be done with PHP's implode() function)?
Thanks! :)
In my database there is a user table, a usergroup table and, since a user can be in multiple usergroups, a user-usergroup table to link the two.
This is they kind of query I want to runSELECT
username,
(SELECT usergroupid FROM `user-usergroup` WHERE userid = 150) AS usergroupids
FROM user WHERE userid = 150
What I would like this query to return is the username and a comma separated list of usergroupids.
Because a subquery is only allowed to return one row, I am wondering if there is some way to compact multiple rows into a string (similar to what can be done with PHP's implode() function)?
Thanks! :)