I've got this table in MS SQL Server Management Studio
+------+-----------+--------
| id | client id | bla bla blaaaa
+------+-----------+--------
| 1 | 1 | .......
| 2 | 2 | .......
| 3 | 3 | .......
| 4 | 8 | .......
| 5 | 9 | .......
| 6 | 15 | .......
| 7 | 1 | .......
| 8 | 16 | .......
| 9 | 2 | .......
| 10 | 9 | .......
| 12 | 12 | .......
+------+-----------+--------
I need to get unique [client id] with max value of [id], like this
+------+-----------+--------
| id | client id | bla bla blaaaa
+------+-----------+--------
| 3 | 3 | .......
| 4 | 8 | .......
| 6 | 15 | .......
| 7 | 1 | .......
| 8 | 16 | .......
| 9 | 2 | .......
| 10 | 9 | .......
| 12 | 12 | .......
+------+-----------+--------
I tried this code, but it doesn't work well .. can someone help me?
SELECT *
FROM table AS one
INNER JOIN table AS two
ON one.[client id] = two.[client id]
WHERE one.[id] > two.[id]
SELECT max(id), client_id, blah_blah
FROM my_table
GROUP BY client_id, blah_blah
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With