我正在尝试从多个表中获取数据,其中我有一个产品,其详细信息分布在多个表中。这是我正在使用的一个查询:
SELECT
fp.id, fp.name, fp.slug, fp.status, fp.approved, fp.created_at, fp.updated_at,
fc.name as cat_name, fc.slug as category_slug,
ff.filepath,
fdp.type, fdp.sku, fdp.regular_price, fdp.sale_price
FROM `foduu_products` fp
JOIN `foduu_category_product` fcp
ON fp.id = fcp.product_id
JOIN `foduu_filemanager` ff
on fp.filemanager_id = ff.id
JOIN `foduu_categories` fc
on fcp.category_id = fc.id
JOIN `foduu_details_product` fdp
ON fp.id= fdp.product_id
where fcp.category_id in (39,155,30,41,51)
group by fdp.product_id <<<<-------------------- Here is the problem
ORDER by fp.id ASC
当我使用GROUP BY
从foduu_details_product
获取数据时,其中包含一个product_id
的多个记录。当我运行此查询时,我收到此错误。
#1055 - Expression #8 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'foduu-ecommerce-cms.fc.name' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
不理解为什么GROUP BY总是给我这些错误。任何建议如何在这里改进我的查询?
这是我的数据库表SQL供参考:
http://vbought.com/products%20table.sql
谢谢(提前)!