My sql query so far has a few joins on tables and the final output looks like this:
FLAG id name
---- --- ----
OK 21 ken
OK 34 mon
OK 51 jil
OK 51 jil
OK 71 jil
OK 80 ron
OK 91 ron
Now I want the FLAGs of duplicate names be shown as ‘dup’ of the lowest id:
FLAG id name
---- --- ----
OK 21 ken
OK 34 mon
OK 51 jil
dup_51 51 jil
dup_51 71 jil
OK 80 ron
dup_80 91 ron
I can do it by using shell/perl script on the records stored in a file, but need to know if it can be possible by manipulating my SQL query.. Thanks for your time and help.
I would suggest a subquery that tracks duplicate entries on
nameand returns the minimumidfor each duplicate. I’ll asume your table is namedtbl:Now you can join this with your original table:
This is a way to do it. Hope it helps you.