My database includes several lookup tables (shown as pulldown menus on the UI form).
For example,
customer_data - customer demographic info.
lookup_car - stores car descriptions (Pinto, Vega, Reliant Robin, Mustang, Corvette)
junction_car_customer - joins a customer with one or more cars
Customer Jeremy Clarkson (cust_id: 1) owns three cars. The dropdown for his record shows:
Pinto (car_id=100)
Reliant Robin (car_id=101)
Vega (car_id=102)
The junction_car_customer data looks like this:
cust_id car_id
1 100
1 101
1 102
I'm trying to return a row showing the customer name and the models owned (as a semi-colon delimited string).
Here's my query:
SELECT
cd.cust_id,
cd.name_first,
cd.name_last,
jcc.car_id,
lc.car_desc
FROM
((customer_data AS cd)
LEFT JOIN ju_cust_car AS jcc ON jcc.cust_id = cd.cust_id)
LEFT JOIN lookup_cars AS lc ON lc.car_id = jcc.car_id
ORDER BY
cd.name_last
This returns:
cust_id name_first name_last car_id car_desc
1 Jeremy Clarkson 100 Pinto
1 Jeremy Clarkson 101 Reliant Robin
1 Jeremy Clarkson 102 Vega
What I'd like is:
cust_id name_first name_last car_desc
1 Jeremy Clarkson Pinto;Reliant Robin;Vega
Is there an efficient way of returning the above result?