Note that there are some explanatory texts on larger screens.

plurals
  1. POStuck again - Need to add another GROUP_CONCAT to MySQL query
    primarykey
    data
    text
    <p>Thank you all for you help on my first attempt</p> <p>I am trying to add a second group_concat to a query to return data to a VB.Net datagrid. I want to rollup the results of 2 columns into new columns kinda like below:</p> <p>Existing data</p> <pre><code>Date Sponsor Match_no Team -------------------------------------------- 1-1-11 Nike 1 Tigers 1-1-11 Nike 1 Bears 2-1-11 Crisco 2 Llamas 2-1-11 Crisco 2 Tigers Date Sponsor Match_no Tags -------------------------------------------- 1-1-11 Nike 1 Away 1-1-11 Nike 1 Rained out 2-1-11 Crisco 2 Home 2-1-11 Crisco 2 Injury </code></pre> <p>and roll both columns up with GROUP_CONCATs to get a result something like this </p> <pre><code> Date Sponsor Match_no Teams_playing Tags ---------------------------------------------------------------- 1-1-11 Nike 1 Tigers vs Bears Away, Rained Out 2-1-11 Crisco 2 Llamas vs Tigers Home, injury </code></pre> <p>I took someone advice here and created join tables on Team_matches and Matches_tags</p> <p>Now there is 7 tables :</p> <pre><code>Dates Sponsors Match Team Tags matches_tags team_matches -------------------------------------------------------------------------------------- Date_id Sponsor_id Match_id Team_id Tag_id Match_id Team_id Date Sponsor_name Match_no Team_name Tag_name Tag_id Match_id date_id sponsor_id </code></pre> <p>My query so far is:</p> <pre><code>select d.date, s.sponsor_name, m.match_no, group_concat(t.team_name separator ' vs ') Teams_playing, group_concat(tg.tag_name separator ' , ') Comments from matchs m inner join matches_teams mte on mte.match_id = m.match_id inner join matches_tags mta on mta.match_id = m.match_id inner join team t on t.team_id = mte.team_id inner join tags tg on tg.tag_id = mta.tag_id inner join sponsors s on s.sponsor_id = m.sponsor_id inner join dates d on d.date_id = s.date_id group by m.match_id, d.date, s.sponsor_name, m.match_no, tg.tag_id </code></pre> <p>and returns results:</p> <pre><code>date sponsor match_no teams playing comments -------------------------------------------------------------------- 1-1-11 Nike 1 Bears vs Tigers Rained out , Rained out 1-1-11 Nike 1 Bears vs Tigers Cancelled , Cancelled 1-1-11 Nike 3 Earwigs vs Goombas Away , Away 2-1-11 Crisco 2 Tigers vs Llamas Away , Away </code></pre> <p>Which is not what im after: </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload