sql - Access 2010 query to Delete where exists not working -
i have join 2 tables , delete 1 table rows not exists in second table. trying query below. should delete 7 records deletes entire persons table.
delete persons.* persons exists ( select persons.[ir number], persons.[last name], persons.[first name], persons.dob, persons.[name type] 1 tblperson right join persons on ( iif(isnull([1tblperson].dob) = true, "01/01/9999", [1tblperson].dob) = iif(isnull(persons.dob) = true, "01/01/9999", persons.dob) ) , ([1tblperson].firstname = persons.[first name]) , ([1tblperson].lastname = persons.[last name]) , ([1tblperson].nametypelit = persons.[name type]) , ([1tblperson].incinmbr = persons.[ir number]) ( ( (persons.[ir number]) in ( select [qryincinmbrsfordelete] ! [incinmbr] [qryincinmbrsfordelete] ) ) , ( (persons.[last name]) not in ( "unknown", "unk", "uknown" ) ) , ((isnull([1tblperson].[incinmbr])) = true) ) ) = true;
edit:
in example... 1, doe, john, 1/1/1960, cust deleted
1tblperson:
incinmbr last name first name dob nametype 1 doe jon 1/1/1960 cust 1 smith john 2/2/1965 emp 1 jones jay 3/3/1965 cust
persons:
incinmbr last name first name dob nametype 1 doe jon 1/1/1960 cust 1 smith john 2/2/1965 emp 1 jones jay 3/3/1965 cust 1 doe john 1/1/1960 cust
the problem you're not telling delete statement delete persons, you're telling delete if sub-query returns results (and understand it, you're expecting return 7?)
if can provide more information keys, can give full solution.
Comments
Post a Comment