Skip to content
Advertisement

SQL: Update all rows except one of each group

I have a table like this. Column “Mail sent” has either the values “0” or a date.

I want to update the “Mail sent” column, so that for every Email there is at most only one date in “Mail sent”. Constraint: The lowest Ordernumber of every Email that has a date should keep the date, the rest should be set to “0”.

The result of the table should be:

Advertisement

Answer

You can use join:

Here is the db fiddle.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement