0
我有兩個表中一個稱爲產品其他product_images。 product_images在此佈局中有6個字段。數據重複後添加新的字段相同product_id
product_id, small_image, medium_image, large_image, width, height
small_image,medium_image和large_image是空字段。
我的數據現在已經重複添加像small_image和large_image具有相同的product_id字段。
我的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_image行是medium_image相關的product_id