Reputation: 7374
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
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
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