Results 1 to 13 of 13
  1. #1
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    409

    delete query not working

    hi, i made a not corresponding value (i hope this is the correct name in english) query, and then i made it a delete query.


    it tells "impossible to delete from the specific table", i think cause two tables are involved, but i've no clue

    Code:
    DELETE IscrittiOCF.*, IscrittiOCFNuovi.NOME, IscrittiOCFNuovi.COGNOME, IscrittiOCFNuovi.DATA_NASCITA, IscrittiOCFNuovi.LUOGO_NASCITA FROM IscrittiOCF LEFT JOIN IscrittiOCFNuovi ON (IscrittiOCF.LUOGO_NASCITA = IscrittiOCFNuovi.LUOGO_NASCITA) AND (IscrittiOCF.DATA_NASCITA = IscrittiOCFNuovi.DATA_NASCITA) AND (IscrittiOCF.NOME = IscrittiOCFNuovi.NOME) AND (IscrittiOCF.[COGNOME] = IscrittiOCFNuovi.[COGNOME]) 
    WHERE (((IscrittiOCFNuovi.NOME) Is Null) AND ((IscrittiOCFNuovi.COGNOME) Is Null) AND ((IscrittiOCFNuovi.DATA_NASCITA) Is Null) AND ((IscrittiOCFNuovi.LUOGO_NASCITA) Is Null));
    thx

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I think the English phrase is unmatched query. You don't change that to a delete query, you use that query as if it were a table, in your delete query. It still may not work if either table lacks a unique index.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    409
    yes, unmatched. I tried to make something like

    Code:
    DELETE * FROM(SELECT IscrittiOCF.*, IscrittiOCFNuovi.NOME, IscrittiOCFNuovi.COGNOME, IscrittiOCFNuovi.DATA_NASCITA, IscrittiOCFNuovi.LUOGO_NASCITAFROM IscrittiOCF LEFT JOIN IscrittiOCFNuovi ON (IscrittiOCF.LUOGO_NASCITA = IscrittiOCFNuovi.LUOGO_NASCITA) AND (IscrittiOCF.DATA_NASCITA = IscrittiOCFNuovi.DATA_NASCITA) AND (IscrittiOCF.NOME = IscrittiOCFNuovi.NOME) AND (IscrittiOCF.[COGNOME] = IscrittiOCFNuovi.[COGNOME])
    WHERE (((IscrittiOCFNuovi.NOME) Is Null) AND ((IscrittiOCFNuovi.COGNOME) Is Null) AND ((IscrittiOCFNuovi.DATA_NASCITA) Is Null) AND ((IscrittiOCFNuovi.LUOGO_NASCITA) Is Null)));
    with no luck, then

    Code:
    DELETE qryCancellaOCF.*FROM qryCancellaOCF;
    with less luck

  4. #4
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I meant
    qry1 is the unmatched query.
    qry2 is the query that has qry1 as the "table" so the sql would look like

    DELETE * FROM qry2;

    If that doesn't work, I'll probably have to leave this for those who have more experience with this. I'm getting rusty when it comes to such things.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Probably you need to use a subquery, review this link for more info:
    https://www.toolbox.com/tech/oracle/...-query-052007/

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  6. #6
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Quote Originally Posted by Gicu View Post
    Probably you need to use a subquery,
    I thought that's what was posted?
    Code:
    DELETE * FROM(SELECT IscrittiOCF.*,
    Admittedly, I gloss over sql like that because it's all Greek to me.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    409
    thanks, i tried to make the same but i think there is some parenthesis problem. I'm really not an expert of subquery but i think it's nice stuff

    Code:
    
    
    DELETE IScrittiOCF.ID FROM IScrittiOCF
    WHERE ((IScrittiOCF.ID) In (SELECT IscrittiOCF.ID, IscrittiOCF.NOME, IscrittiOCF.COGNOME, IscrittiOCF.DATA_NASCITA, IscrittiOCF.LUOGO_NASCITA, IscrittiOCF.PROVINCIA_NASCITA, IscrittiOCF.INDIRIZZO, IscrittiOCF.CIVICO, IscrittiOCF.CAP, IscrittiOCF.COMUNE, IscrittiOCF.PROVINCIA, IscrittiOCF.DENOMINAZIONE_SOGGETTO_ABILITATO, IscrittiOCF.REGIONE, IscrittiOCF.[Data/ora creazione], IscrittiOCF.[Data/ora modifica]
    FROM IscrittiOCF LEFT JOIN IscrittiOCFNuovi ON (IscrittiOCF.[COGNOME] = IscrittiOCFNuovi.[COGNOME]) AND (IscrittiOCF.NOME = IscrittiOCFNuovi.NOME) AND (IscrittiOCF.DATA_NASCITA = IscrittiOCFNuovi.DATA_NASCITA) AND (IscrittiOCF.LUOGO_NASCITA = IscrittiOCFNuovi.LUOGO_NASCITA)
    WHERE (((IscrittiOCFNuovi.NOME) Is Null) AND ((IscrittiOCFNuovi.COGNOME) Is Null) AND ((IscrittiOCFNuovi.DATA_NASCITA) Is Null) AND ((IscrittiOCFNuovi.LUOGO_NASCITA) Is Null));

  8. #8
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Can you please try this:
    Code:
    DELETE * FROM IScrittiOCF
    WHERE IScrittiOCF.ID In (SELECT IscrittiOCF.ID FROM IscrittiOCF LEFT JOIN IscrittiOCFNuovi ON IscrittiOCF.[COGNOME] = IscrittiOCFNuovi.[COGNOME] AND IscrittiOCF.NOME = IscrittiOCFNuovi.NOME AND IscrittiOCF.DATA_NASCITA = IscrittiOCFNuovi.DATA_NASCITA AND IscrittiOCF.LUOGO_NASCITA = IscrittiOCFNuovi.LUOGO_NASCITA WHERE IscrittiOCFNuovi.NOME Is Null AND IscrittiOCFNuovi.COGNOME Is Null AND IscrittiOCFNuovi.DATA_NASCITA Is Null AND IscrittiOCFNuovi.LUOGO_NASCITA Is Null);
    @Micron - it was close but it missed the .ID IN (Select.....

    Cheers,
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Get the select working first, then surround it with the delete syntax.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    You shouldn't need a subquery to do this.
    As your original query has more than one table, use DELETE DISTINCTROW so Access is working with unique records.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  11. #11
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    409
    it worked! now i will dig in my mistake, subquery are really useful

  12. #12
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    409
    thanks isladogs, you mean that in this way i can delete the records that appears just once in the query that includes two tables?

  13. #13
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    Whilst subqueries are very useful, they are slow and should only be used if a simpler solution isn't available

    If your unmatched delete query is correctly written, then using DELETE DISTINCTROW should allow you to delete all unmatched records at once.
    However, as with any DELETE query you should check the records affected carefully before running the query. Possibly test on a backup copy first.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

Similar Threads

  1. Delete query not working
    By Euler271 in forum Queries
    Replies: 2
    Last Post: 03-27-2018, 11:47 AM
  2. Delete query working very slow
    By jaryszek in forum Queries
    Replies: 1
    Last Post: 07-27-2017, 02:52 AM
  3. Replies: 1
    Last Post: 01-16-2013, 10:58 AM
  4. Replies: 4
    Last Post: 08-14-2012, 11:56 AM
  5. Replies: 0
    Last Post: 04-08-2010, 12:22 PM

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