我有两个用于属性和图像的表,它们在两个表中具有相同的列名,例如 id,name。父列是图像中的外键。
SELECT DISTINCT(A.id),A.name,B.name AS img
FROM `jos_properties_products` AS A
LEFT JOIN `jos_properties_images` AS B ON A.id = B.parent
从上面我想删除重复的。
我有两个用于属性和图像的表,它们在两个表中具有相同的列名,例如 id,name。父列是图像中的外键。
SELECT DISTINCT(A.id),A.name,B.name AS img
FROM `jos_properties_products` AS A
LEFT JOIN `jos_properties_images` AS B ON A.id = B.parent
从上面我想删除重复的。
试试这个 :
SELECT A.id,A.name,max(B.name) AS img
FROM `jos_properties_products` AS A
LEFT JOIN `jos_properties_images` AS B ON A.id = B.parent
group by A.id,A.name
SELECT DISTINCT(A.id) as ids,A.name aName,B.name AS img FROM jos_properties_products
AS A LEFT JOIN jos_properties_images
AS B ON A.id = B.parent group by ids,aName,img;
我认为这会做