SQL Select Distinct仍显示重复项

时间:2016-05-04 03:03:48

标签: sql sql-server sql-server-2008

我使用DISTINCT子句进行了以下查询,但结果仍显示重复的ID&#39>:

SELECT DISTINCT 
    rl.countryid, rl.resellerid, c.countryname, c.iso2, r.resellerid 
FROM reseller_locator rl 
INNER JOIN countries c 
    ON rl.countryid = c.countryid
LEFT JOIN resellers r 
    ON r.parentid = 7 
WHERE 
    rl.resellerid = 7 
    OR rl.resellerid = r.resellerid

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:5)

DISTINCT与指定的所有列有关,因此,如果您有2个记录具有相同的countryid但不同的resellerid,两者都将显示。