0

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?

2
  • It would be better if you explain with a proper data set and expected results. Commented Feb 2, 2016 at 18:17
  • okay. Say I have a table which has two subject codes and the table has values say (A, B), (A, C), (A, D), (B, A), etc. Now how do I remove the (B, A) if (A, B) is already present? Commented Feb 2, 2016 at 18:19

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.