Click here to Skip to main content
15,890,717 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to delete last record where product ID and userID are specified.

my current code is
delete top (1) from ShoppingBasket where productID=1 AND userID='admin' 


but this deletes the first not the last record, and using 'order by desc' does not work.
Posted
Comments
Saintd81 4-Dec-12 15:11pm    
What does the table structure look like for your ShoppingBasket table?

SQL
delete from ShoppingBasket where productID=1 AND userID='admin' order by (your id column) desc limit 1
 
Share this answer
 
Here is an alternative but I like wizardzz solution best. This basically an expansion of wizzardzz solution and may be easier to understand!

SQL
DELETE  FROM shoppingBasket
WHERE   ID IN (SELECT TOP 1
                      ID
               FROM   shoppingBasket
               WHERE  ProductID = 1
                      AND UserID = 'Admin'
               ORDER BY ID DESC)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900