如果您想保留最新的友谊ID,请执行以下操作
CREATE TABLE temp_table AS (SELECT * FROM table);
DELETE FROM table WHERE friendshipid NOT IN (SELECT friendshipid FROM (SELECT * FROM temp_table ORDER BY friendshipid DESC) as temp_table GROUP BY userid, friendwith);
DROP TABLE temp_table ;
或者,如果您想保留最古老的友谊 ID,请执行以下操作
CREATE TABLE temp_table AS (SELECT * FROM table);
DELETE FROM table WHERE friendshipid NOT IN (SELECT friendshipid FROM (SELECT * FROM temp_table ORDER BY friendshipid ASC) as temp_table GROUP BY userid, friendwith);
DROP TABLE temp_table ;