Reputation: 4053
Here's the query:
SELECT ActionTicketID, OrderTicketID, BarCode, MAX(ID) AS ID, TicketBarCode
FROM Table
where ActionTicketID = 26250347
GROUP BY ActionTicketID, OrderTicketID, BarCode, ID, TicketBarCode
The result looks as the following:
As you can see I get 3 rows, but need only one where ID is max. I think it is because of ActionTicketID is the same.
How to achieve it?
Upvotes: 1
Views: 48
Reputation: 9335
Try order by
;
SELECT top 1 ActionTicketID, OrderTicketID, BarCode, ID, TicketBarCode
FROM Table
where ActionTicketID = 26250347
order by ID desc
Upvotes: 1