šljaker
šljaker

Reputation: 7374

tsql - delete last row

I want to delete the last row from the table that satisfies some condition.

DELETE TOP 1 FROM SOME_TABLE
WHERE SOME_COULMN = @VALUE
ORDER BY 1 DESC

Upvotes: 5

Views: 5801

Answers (2)

Michel P.
Michel P.

Reputation: 23

DELETE and UPDATE statements require parentheses () for the number of rows argument

DELETE TOP (1) FROM SOME_TABLE WHERE SOME_COULMN = @VALUE ORDER BY 1 DESC

Upvotes: -1

Chris Latta
Chris Latta

Reputation: 20560

DELETE FROM SOME_TABLE
WHERE UNIQUE_ID = 
(SELECT TOP 1 UNIQUE_ID
FROM SOME_TABLE
WHERE SOME_COLUMN = @VALUE
ORDER BY SOMETHING DESC)

Upvotes: 7

Related Questions