简体   繁体   English

MYSQL列出所有类别的所有产品

[英]MYSQL List all products with all categories

I have this schema: 我有这个架构:

table_products : product_id, name, price, table_products :product_id,名称,价格,

table_categories : category_id, name, table_categories :category_id,名称,

table_categories_products : category_id, product_id table_categories_products :category_id,product_id

I want list all products from my db including all the categories of each product. 我想列出数据库中的所有产品,包括每个产品的所有类别。

Actually i use this query: 实际上我使用此查询:

SELECT p.id, p.name, p.price, GROUP_CONCAT(c.category_id, ';', c.name SEPARATOR ',')
FROM table_products
LEFT JOIN table_categories_products tcp ON tcp.product_id=p.product_id
LEFT JOIN table_categories c ON c.category_id=p.product_id
GROUP BY p.id

The problem is that one product could be inside unlimited categories and the group_concat has a size limit. 问题在于,一个产品可能属于无限类别,并且group_concat具有大小限制。

Update 更新

I had already considered the option of increase "group_concat_max_len", but dont't allow for an infinite string 我已经考虑过增加“ group_concat_max_len”的选项,但不允许使用无限字符串

You can change group_concat max size by : 您可以通过以下方式更改group_concat的最大大小:

SET [GLOBAL | SESSION] group_concat_max_len = val;

default is 1024, and maximal settable value is 1073741824 默认值为1024,最大可设置值为1073741824

at least that is what doc says: http://dev.mysql.com/doc/refman/5.7/en/group-by-functions.html#function_group-concat 至少文档是这样说的: http : //dev.mysql.com/doc/refman/5.7/en/group-by-functions.html#function_group-concat

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM