[英]data duplicates after adding new fields with the same product_id
我有兩個表,一個稱為產品,另一個稱為product_images。 product_images在此布局中有6個字段。
product_id, small_image, medium_image, large_image, width, height
small_image,medium_image和large_image是空字段。
添加具有相同product_id的額外字段(如small_image和large_image)后,我的數據現在已重復。
我的SQL語句
"SELECT *,
i.medium_image, i.width, i.height,
COALESCE((SELECT COUNT(*)
FROM order_details od
WHERE od.product_id = p.product_id), 0) as most_popular
FROM products p
INNER JOIN product_images i on i.product_id = p.product_id
WHERE p.department_id=:department_id AND p.is_active=1
$orderby
LIMIT :limit OFFSET :offset");
我需要做些什么來更改我的sql語句,以便僅選擇產品的medium_image,這樣它就不會重復,我嘗試使用DISTINCT,但這不起作用。 我只想返回與product_id相關的medium_image的單個product_image行
嘗試添加
GROUP BY product_id
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.