Q:

multi dimensional mysql select?

table: car_profile
carid, carname, caryear, cartype

table: user_profile
userid, username, useremail

table: user_car
id, carid, userid, status
FC: carid, userid

One carid can have multiple userid in table user_car (One car can be used by multiple persons)
Given a carid, I want to select caryear, cartype, [userid, username, useremail]. The one inside the bracket should be an array in itself, as multiple userid is possible. I am not sure if this is posisble?

A:

SELECT can return a single value, a row of values, or a table of rows. There is no higher dimensional option. Below, the multiple userid, username, useremail will show up on separate rows.
SELECT cp.caryear, cp.cartype, up.userid, up.username, up.useremail
FROM car_profile as cp
LEFT JOIN user_car as uc
ON uc.carid = cp.carid 
LEFT JOIN user_profile as up
ON uc.userid = up.userid
WHERE cp.carid = carid
ORDER BY cp.caryear, cp.cartype

