you can use GREATEST and LEAST to “arrange” your columns, and then use different ones:
SELECT DISTINCT GREATEST(col1, col2) as first, LEAST(col1, col2) as second from yourTable
This will give you a great result. If you want to delete, you can delete everything that is not in this result:
DELETE FROM yourTable where (col1, col2) NOT IN (
SELECT DISTINCT GREATEST(col1, col2) as first, LEAST(col1, col2) as second from yourTable
)
source
share