与其他表格我有像
这样的表格rowsid source_row same_as_row
row1 1 18
row2 3 18
row3 18 1
row4 18 3
我只想删除第3行和第4行:
row3 18 1
row4 18 3
哪个查询!删除查询第3行和第4行.help
答案 0 :(得分:2)
DELETE FROM table
GROUP BY sourcerow
HAVING COUNT(*) > 1
它应该这样做,假设您只在sourcerow
列
答案 1 :(得分:1)
编辑:让我失望(之前的答案已删除)
由于双嵌套有效,这就是我这样做的方式(尽管从逻辑的角度来看,它的一部分是高度冗余的)
DELETE
yourTable
FROM
yourTable
INNER JOIN
(SELECT * FROM (SELECT same_as_row FROM yourTable GROUP BY same_as_row)) as lookup
ON lookup.same_as_row = yourTable.source_row
WHERE
source_row > same_as_row
答案 2 :(得分:1)
select
rowsid, source_row, same_as_row
from tablename t1
where not exists
(
select * from tablename t2
where t2.source_row = t1.same_as_row and t2.same_as_row = t1.source_row and t1.rowsid > t2.rowsid)
)
答案 3 :(得分:0)
DELETE FROM table GROUP BY rowsid,source_row,same_as_row 有计数(*)> 1