I have a table in MySQL database. which is having 3 records shown below.
The table :
columns | name | address | phone | comments |
---|---|---|---|---|
1st record | raj | Chennai | 232329 | null |
2nd record | raj | Chennai | 232329 | null |
3rd record | raj | Chennai | 232329 | null |
I want to update comments column as duplicate records for two records only.
The output should be like this….
The table
columns | name | address | phone | comments |
---|---|---|---|---|
1st record | raj | Chennai | 232329 | duplicate records |
2nd record | raj | Chennai | 232329 | duplicate records |
3rd record | raj | Chennai | 232329 | null |
pls tell me how to do this in MySQL.
2
Answers
This can be done as follows :
First, we need to most recent record for each group:
Then we use
left join
to identify all records except the latest id of that group :Demo here