I have table like this
id | serial_num | version | .....
1 | 1 | 1 | .....
2 | 2 | 1 | .....
3 | 2 | 2 | .....
4 | 3 | 1 | .....
5 | 4 | 1 | .....
6 | 5 | 1 | .....
7 | 5 | 2 | .....
8 | 5 | 3 | .....
Now what I want to select is to get rows with max version and unique serialn_num …
The result would be:
id | serial_num | version | .....
1 | 1 | 1 | .....
3 | 2 | 2 | .....
4 | 3 | 1 | .....
5 | 4 | 1 | .....
8 | 5 | 3 | .....
My SQL is a bit more complicated and that is why I don’t solve the problem by using MAX()… I have few left joins etc …
any ideas?
Best regards and thank you for your time!
Try this:
Subquery will return the maximum version for serial_num, so this will return all rows where serial_num has the maximum value. See this fiddle.