[英]SQL JOIN query to get data with GROUP BY on one table only
我正在嘗試從多個表中獲取數據,在該表中我有一種產品,其詳細信息分布在多個表中。 這是我正在使用的一個查詢:
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
先感謝您)!
您的查詢中沒有任何聚合函數,因此首先應質疑此特定語句的使用。
您位於“ sql_mode = only_full_group_by”中,因此必須在group by語句中的select中重復使用未在聚合函數(Max,Sum,Count ...)中使用的每一列。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.