php - SQL Left join Many to Many, only display distinct ID in left table -
tablea id name 1 peter 2 mary 3 john tableb id event 1 eventa 2 eventb 3 eventc tablec id aid bid 1 1 1 2 1 3 3 2 1 i doing this select distinct a.id, b.id tablea left join tablec c on a.id = c.aid left join tableb b on c.bid = b.id it shows 1 peter eventa 1 peter eventc i want output follows 1 peter eventa eventc how that? many thanks. amendment: actually displaying records below: 1 peter eventa eventc from suggestion works fine, wanna add hide show function. function reversedisplay(d) { if(document.getelementbyid(d).style.display == "none") { document.getelementbyid(d).style.display = "block"; } else { document.getelementbyid(d).style.display = "none"; } } select distinct a.id, b.id, b.event from tablea a left join tablec c on a.id = c.aid left join tableb b on c.bid = b.id $lastid = ""; while($row = mysql_fetch_array($rs)) { if ($lastid != $row[0]){ ...