Delete query
My query is the following :
SELECT [orders].[orderid], [orders].
WHERE ((([orders].
I have to build a delete query deleting all the previous orders where Audit = True and Customerid = 121.
I need help
delete from Orders
where CustomerId = 121 and OrderID <> (select max(OrderId) from Orders where CustomerID = 121)
Looking for relevant Database Whitepapers? Visit the SearchOracle.com Research Library.
Mrdenny | Apr 18 2008 6:10PM GMT
Check out my SQL Server blog “SQL Server with Mr Denny” for more SQL Server information.
Dwaltr | Apr 18 2008 6:40PM GMT
Are you entering the data via a form? If so you can use the Before Insert event (in the Form Property Sheet) to delete all the data prior to inserting the new row. That eliminates the subquery, making your delete statement look like this:
delete from orders where audit=True and customerid = 121 (or Formname.CustomerID)
Using the formname.customerid will allow it to work for whatever customer id is on the form.