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

    multimatch query not working

    hi, i use this query to delete records that are not present in the second table

    Code:
    DELETE *
    FROM ISCRITTIOCFNUOVI
    WHERE IScrittiocfnuovi.id IN
    (SELECT IScrittiocfnuovi.id
    FROM IScrittiocfnuovi LEFT JOIN IscrittiOCFTemp ON (IScrittiocfnuovi.nome = IscrittiOCFTemp.nome) AND (IscrittiOCFTemp.cognome = IScrittiocfnuovi.cognome) AND (IscrittiOCFTemp.data_nascita = IScrittiocfnuovi.data_nascita) AND (IscrittiOCFTemp.luogo_nascita = IScrittiocfnuovi.luogo_nascita)
    WHERE IscrittiOCFTemp.nome is null AND IscrittiOCFTemp.cognome is null AND IscrittiOCFTemp.data_nascita is null AND IscrittiOCFTemp.luogo_nascita is null);
    but it finds records that actually are in both table.
    Where is the problem?


    thanks

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    I would expect you should be using NOT IN ?
    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

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    You also need to alias IScrittiocfnuovi in the sub query

  4. #4
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    434
    i got the problem, i think the database was corrupting.
    I exported everything and the query works fine now.
    Do you think i have to do something more or my db is fine now?

  5. #5
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    Do you think i have to do something more or my db is fine now?
    impossible to say without knowing what changes you have actually done, what your data actually is and what caused the corruption. db’s usually corrupt because of something you have done or the setup is wrong - such as not split and you have multiple users)

  6. #6
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    434
    well, maybe i messed up something but now it's fine.
    I'll see if everything is fine on the medium period
    thanks

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    I do not see how, you say not in other table, but then compare sub query with IN ?

    Doing the opposite I would have thought?
    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

  8. #8
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    434
    This is my new delete query
    Code:
    DELETE *FROM ISCRITTIOCFNUOVI
    WHERE IScrittiocfnuovi.id IN
    (SELECT id
    FROM qryOCFNuoviNPTemp
    );

    The base query (qryOCFNuoviNPTemp) is this one

    Code:
    SELECT ISCRITTIOCFNUOVI.id, ISCRITTIOCFNUOVI.Nome, ISCRITTIOCFNUOVI.Cognome, ISCRITTIOCFNUOVI.Data_nascita, ISCRITTIOCFNUOVI.Luogo_nascitaFROM ISCRITTIOCFNUOVI LEFT JOIN iscrittiocftemp ON (ISCRITTIOCFNUOVI.Nome = ISCRITTIOCFTEMP.Nome) AND (ISCRITTIOCFNUOVI.Cognome = ISCRITTIOCFTEMP.Cognome) AND (ISCRITTIOCFNUOVI.Data_nascita = ISCRITTIOCFTEMP.Data_nascita) AND (ISCRITTIOCFNUOVI.Luogo_nascita = ISCRITTIOCFTEMP.Luogo_nascita)
    WHERE ISCRITTIOCFTEMP.Nome IS NULL
    AND ISCRITTIOCFTEMP.cogNome IS NULL
    AND ISCRITTIOCFTEMP.data_nascita IS NULL
    AND ISCRITTIOCFTEMP.luogo_nascita IS NULL;
    I had to make the base query separately cause if i put the sql of the base directly in the delete query sometimes i got records that should be not in, sometimes it works fine.
    How is this possible?
    I made new tables and copied records in them, after exported in another DB all the tables (before i exported my front end)

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    How is this possible?
    You do not know your data? SQL can only do what you instruct.

    I would always start with a Select to see I get the expected data, and only then change to Append/Delete etc.
    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
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    434
    i DO know my data, and i always start with a select query.
    But before i got different results without any clear reason, now it seems fixed after exportation, but i'll keep an eye on that
    thanks

  11. #11
    diegomarino is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Feb 2018
    Posts
    434
    it was a problem of the db, i exported everything in another and now it works.

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

Similar Threads

  1. Replies: 17
    Last Post: 05-10-2020, 09:49 AM
  2. Replies: 2
    Last Post: 03-26-2019, 12:40 PM
  3. Working query stops working after importing
    By Abacus1234 in forum Import/Export Data
    Replies: 3
    Last Post: 10-25-2015, 09:12 PM
  4. Query Not working
    By keiath in forum Queries
    Replies: 3
    Last Post: 02-28-2014, 10:05 AM
  5. Replies: 3
    Last Post: 10-17-2012, 09:24 AM

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