I have a table like:
id(int) flag(int) price(float)
1 0 50
2 400
3 4 200
4 3 150
5 3 100
6 3 400
7 2 120
I’d like to select all rows that have distinct flag, choosing the lowest price on every group of flag
So, in this example I’d get:
id(int) flag(int) price(float)
1 0 50
2 400
3 4 200
5 3 100
7 2 120
Note that flag is not mandatory, so it can have a value (int) or nothing (null).
Regards
EDIT:
Just to make it mre clear.
I want to select all the rows that have an id and a price, all of them, without filtering by price.
Then I’d like to join only the row with the lowest price from each group of flags
And here’s an sqlfiddle for it.