找到相同的行:
SELECT * FROM dept a
WHERE ROWID <> (SELECT MAX(ROWID)
FROM dept b
WHERE a.deptno = b.deptno
AND a.dname = b.dname -- Make sure all columns are compared
AND a.loc = b.loc);
注释:
如果只找deptno列相同的行,上面的查询可以改为:
SELECT * FROM dept a
WHERE ROWID <> (SELECT MAX(ROWID)
FROM dept b
WHERE a.deptno = b.deptno)
删除相同的行:
DELETE FROM dept a
WHERE ROWID <> (SELECT MAX(ROWID
FROM dept b
WHERE a.deptno = b.deptno
AND a.dname = b.dname -- Make sure all columns are compared
AND a.loc = b.loc);
注意:上面并不删除列值为null的行。
阅读(1088) | 评论(0) | 转发(0) |