mysql - How to join compound tables -
i have 2 tables (simplified below)
**classes** **locations** [classname][locationid][time] [id][locationname][address] classa 1 1pm 1 locationa 123 classb 2 2pm 2 locationb 456 classc 2 3pm classd 1 2pm
i not sure how word this...i want create select statement, can have of classes grouped location, without duplicating location data. if use:
select * classes inner join locations on classes.locationid = locations.id
i end result 4 rows. how can result 2 rows? (ex locationa containing classa , classd, without getting duplicate location data)
is cannot done in straight mysql? if so, can manage in php.
use group_concat
select l.locationname, group_concat(distinct c.classname) locations l inner join classes c on c.locationid = l.id group l.locations
Comments
Post a Comment