Results 1 to 6 of 6
  1. #1
    Edward_ is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Apr 2014
    Posts
    38

    Simple Delete query syntax help needed.

    I had a full question prepared showing my non-working delete query prepared, but I think it will be simpler to just show a working select query I have that selects the records I want to delete instead.



    My working Select query:
    Code:
    SELECT [Order Details].[Product ID], [Order Details].[Order ID], Products.[Product ID], Products.[Product Name], Products.[Units In Stock]FROM [Order Details] RIGHT JOIN Products ON [Order Details].[Product ID] = Products.[Product ID]
    WHERE ((([Order Details].[Order ID]) Is Null) AND ((Products.[Product ID]) Like "VD-*") AND ((Products.[Units In Stock])=0))
    WITH OWNERACCESS OPTION;
    What I can't seem to do is convert the above SELECT to the delete sequence of: Delete, From, Where

    I simply want the new delete query to delete the records found in the Products query only, using the above criteria.

    Any advice greatly appreciated.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Just so you understand that select queries don't always work as Action queries. Select queries are read only queries and Action queries require writing to the Recordset. You can read an ambiguous query but not write to the same.
    That being said...maybe some query guru will jump in with a solution for you.

  3. #3
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    You have two tables in the select statement. A delete can only work on one table at a time.
    Code:
     DELETE  [Order Details].*
    FROM [Order Details] RIGHT JOIN Products ON [Order Details].[Product ID] = Products.[Product ID] 
    WHERE ((([Order Details].[Order ID]) Is Null) AND ((Products.[Product ID]) Like "VD-*") AND ((Products.[Units In Stock])=0))
    WITH OWNERACCESS OPTION;


    Make sure you have a back up, and test that this is doing what you want.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Can you tell us the "business rationale" (simple English) behind this request?
    How can the OrderDetails have a NULL Order ID?
    You want to delete the OrderDetails, or ????

    Can you show us your relationships window as a jpg?

  5. #5
    Edward_ is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Apr 2014
    Posts
    38
    Can you tell us the "business rationale" (simple English) behind this request?
    How can the OrderDetails have a NULL Order ID?
    You want to delete the OrderDetails, or ????
    My rationale behind this is to reduce db size by eliminating countless unused legacy product records.
    My Order Details will have a Null OrderID if no Order detail exists containing a certain product ID(no order has the Product ID in question)
    (this selection method is acceptable in my Select query.)

    You have two tables in the select statement. A delete can only work on one table at a time.
    Is this true If I'm basing the criteria on Table-1, but deleting only from Table-2 also?
    I am wanting to delete from only One Table.

    Attachment 32426

    Edit:

    This is my latest attempt:
    Code:
    DELETE Products.*
    FROM Products RIGHT JOIN [Order Details] ON Products.[Product ID] = [Order Details].[Product ID]
    WHERE ((([Order Details].[Order ID]) Is Null) AND ((Products.[Product ID]) Like "VD-*") AND ((Products.[Units In Stock])=0))
    WITH OWNERACCESS OPTION;
    Result:
    'Could not delete from specified tables'

  6. #6
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Have you tried simply using the query builder - get your select correct, and then use the query builder to change the query to a Delete query?
    Or using the ID and an IN clause to find the id's based on your current select query.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 06-04-2015, 09:46 AM
  2. Replies: 2
    Last Post: 05-09-2015, 01:34 PM
  3. Delete Query Help Needed
    By tushar05 in forum Queries
    Replies: 1
    Last Post: 08-05-2011, 05:34 PM
  4. Simple help needed
    By canfish in forum Database Design
    Replies: 10
    Last Post: 07-28-2010, 05:13 PM
  5. if or syntax help needed
    By techexpressinc in forum Queries
    Replies: 16
    Last Post: 01-11-2010, 08:03 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums