我有两个属性和图像表,它们具有相同的列名,如两个表中的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
从上面我想删除重复。
答案 0 :(得分:1)
试试这个:
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
答案 1 :(得分:0)
SELECT DISTINCT(A.id)as ids,A.name aName,B.name AS img
来自jos_properties_products
AS A
LEFT JOIN jos_properties_images
AS B ON A.id = B.parent group by ids,aName,img;
我认为这样做