How do I write a delete statement in Access SQL?

D

Dave

The following will work in T-SQL:

DELETE FROM orders
FROM orders o INNER JOIN orderdetail od ON o.orderid=od.orderid
WHERE od.billitem='a2220'


But I get an error referencing the FROM clause when I try it in Acesss.

How do I write a DELETE in Access that references more than one table?
 
B

Bill Edwards

DELETE tblOrders.*
FROM tblOrders
INNER JOIN tblOrderDetail ON tblOrders.OrderId = tblOrderDetail.OrderId
WHERE tblOrderDetail.BillItem = "a2220"

Or use the query designer to build the query and then change the query type
to "Delete Query"
 
C

Chris Nebinger

Bill's code will work, but here's why you got the error.

Access allows aliasing fields or tables, but you have to
use the AS keyword.

DELETE FROM orders
FROM orders AS o INNER JOIN orderdetail AS od ON
o.orderid=od.orderid
WHERE od.billitem='a2220'

Chris Nebinger
 
D

Dave

Thanks guys for your help

Dave

Bill Edwards said:
DELETE tblOrders.*
FROM tblOrders
INNER JOIN tblOrderDetail ON tblOrders.OrderId = tblOrderDetail.OrderId
WHERE tblOrderDetail.BillItem = "a2220"

Or use the query designer to build the query and then change the query type
to "Delete Query"
 
C

Chris Nebinger

Bah, sticky fingers......


Delete * from Orders as o inner join orderdetail as od on
o.orderid=od.orderid where od.billitem='a2220'


Or:

Delete * from orders where orderid in (Select OrderId from
orderdetail where billitem='a2220')


Chris Nebinger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top