Search code examples
mysqlsql-delete

row deletion in mysql


I have a table say incompatible which has two columns namely codeA and codeB. Now, I have two entries as A, B and B, A if A is incompatible to B. My question is how do I remove one of the rows from the table in mysql?


Solution

  • Try this:

    DELETE t1 FROM incompatible AS t1
    INNER JOIN incompatible AS t2 ON t1.codeA = t2.codeB AND t2.codeB = t1.codeA 
    WHERE t1.codeA > t1.codeB
    

    Demo here