MySQL GROUP_CONCAT getting data from 2 tables and linking table
<p>I am trying to use MySQL GROUP_CONCAT to aggregate data from 2 tables linked by a linking table. I would like to display useful data rather than just ids.</p>

<p>If I do the following query:</p>

<p><code>SELECT pid, group_concat(vid) FROM bs_prod_vars GROUP BY pid</code></p>

<p>I correctly get the following:</p>

<pre><code>pid     group_concat(vid)
---------------------------------------
1       1,2,3,4,5,6
2       9,10,11,4,12,8,6,1,2,5,3,7
3       2,13,3,1,11,4,6,10,9,5,12,8,7
4       2,6,5,3,4,1
5       1,11,3,12,5,9,10,6,8,4,13,2,7
8       14
</code></pre>

<p>If I do this:</p>

<pre><code>SELECT p.name, group_concat(v.name) 
FROM bs_products p, bs_variations v, bs_prod_vars pv 
WHERE pv.pid = p.id 
AND pv.vid = v.id 
GROUP BY p.name
</code></pre>

<p>I only get 2 rows as follows:</p>

<pre><code>name                group_concat(v.name)
-------------------------------------------------------------
Test Product A      Pre-2012
Test Product B      2008 - 2010,2002 - 2012,From 2011,2002...
</code></pre>

<p>What am I doing wrong with my second query?</p>