如何消除以下SQL数据值的重复?

时间:2013-12-25 02:31:24

标签: php mysql sql

我需要消除NIC Number重复的情况。请为我提供SQL查询。

enter image description here

2 个答案:

答案 0 :(得分:1)

DELETE FROM Table_Name A
INNER JOIN (SELECT NIC, COUNT(*) AS RecCount, MIN(RESULT) AS OlderValue 
            FROM Table_Name 
            GROUP BY NIC) b
ON A.NIC = b.NIC 
AND a.RESULT != b.OlderValue

答案 1 :(得分:0)

WHILE EXISTS (SELECT NIC FROM TABLE_NAME
              HAVING COUNT(NIC) > 1)
DELETE TOP 1 FROM TABLE_NAME WHERE NIC IN (SELECT NIC FROM TABLE_NAME HAVING COUNT(NIC) > 1) ORDER BY SubjectID DESC