Search code examples
sqlsqlitedb-browser-sqlite

Change duplicate value in a column


Can you please tell me what SQL query can I use to change duplicates in one column of my table? I found these duplicates:

SELECT Model, count(*) FROM Devices GROUP BY model HAVING count(*) > 1;

I was looking for information on exactly how to change one of the duplicate values, but unfortunately I did not find a specific option for myself, and all the more information is all in abundance filled by deleting the duplicate value line, which I don't need. Not strong in SQL at all. I ask for help. Thank you so much.


Solution

  • After the command:

    SELECT Model, count (*) FROM Devices GROUP BY model HAVING count (*)> 1;
    

    i get the result:

    • 1895 lines = NULL;
    • 3383 lines with duplicate values;
    • and all these values are 1243.

    after applying your command:

    update Devices set
      Model = '-'
    where id not in
      (select
         min(Devices .id)
       from Devices 
       group by Devices.Model)
    

    i got 4035 lines changed. if you count, it turns out, (3383 + 1895) = 5278 - 1243 = 4035 and it seems like everything fits together, the result suits, it works.