Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL Delete rows if 2 rows equal

I have a table like this:

id column2 column3 column4
1 value1 value2 somevalue
2 value3 value4 somevalue
3 value5 value5 somevalue

I want to delete any rows in the table where column 2 is equal to column 3.
My table is 3000 rows long, and i want to perform this for every row that has the same value in column 2 and column 3. in this example, the row with value5 in column 2 and 3 would be deleted.

ive tried

DELETE FROM exampleTable t1 
WHERE EXISTS (SELECT 1 from Table t2
              WHERE t1.column2= t2.column3
              AND t2.Id = t1.Id) 

with no success. any help would be great thank you

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Since it is in the same table, it can be done way easier:

DELETE FROM exampleTable WHERE column2 = column3

Fiddle

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading