我有两张桌子product
,specs
如果至少有一个规格与 WHERE 匹配,我想获得产品和 group_concat(所有规格)。这是我到目前为止所拥有的,但它只返回与 WHERE 匹配的一个规范。
select p.ID, p.name, p.manufacturer GROUP_CONCAT(s.specValue order by s.pID,',')
from product as p
JOIN spec AS s ON p.ID = s.pID
WHERE s.specValue = 'micro'
group by p.ID
product table
| ID | name | manufacturer |
| 1 | Iphone | apple |
| 2 | galaxy | samsung |
| 3 | note | samsung |
------------------------------
spec table
| ID | pID | specName | specVlaue |
| 1 | 1 | charger | bad |
| 2 | 2 | charger | micro |
| 3 | 2 | keypad | touch |
| 4 | 4 | charger | micro |
-----------------------------------