Some times we need to remove rows with multiple duplicate columns as shown in the table below,See the last two rows with same values.

ID           college   courses 
183             24        102         
151             24         52           
155             24         66           
179             24         66           

With the help of temporary table we can remove rows and here is the query to remove the rows

CREATE TABLE temp_table AS (SELECT * FROM table);
DELETE FROM table WHERE ID NOT IN 
(SELECT ID FROM (SELECT * FROM temp_table ORDER BY ID DESC) 
as temp_table GROUP BY college, courses);
DROP TABLE temp_table ;

Hope it helps to remove rows with multiple duplicate columns

Leave a Reply

Your email address will not be published. Required fields are marked *