I'm searching for a SQL command that does the following:
From every set of rows with the same value in column A delete all rows but the row with the highest value in column B. If there are multiple rows with the same B value in a set keep at least one of them.
Additional notes
- The column format should not be modified nor additional tables should be required to achieve the desired result.
- The table has only two columns from which none is primary, unique or multiple occurrences key.
- The query should work well with bigger datasets i.e. the running time should be proportional to the number of rows in the table (not quadratic/exponential).
Example:
Initial state:
+---+---+
| A | B |
+---+---+
| x | 1 |
| x | 2 |
| y | 3 |
+---+---+
Desired result:
+---+---+
| A | B |
+---+---+
| x | 2 |
| y | 3 |
+---+---+