Delete query cannot find required entry

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AbbasBD
    New Member
    • Aug 2010
    • 11

    Delete query cannot find required entry

    I want to delete entry in table [tBuy Invoice] where linked table [tBuys] has no record. Statement is -
    -----------
    DELETE [tBuy Invoice].*
    FROM [tBuy Invoice]
    WHERE ((([tBuy Invoice].BuyInvcID)
    In (
    SELECT [tBuys].[BuyInvcID]
    FROM [tBuys]
    WHERE [tBuys].[BuyID] Is Null
    )));
    -------------
    But the Delete query do not find any entry. I think it is because 'Is Null' do not return 'no entry list', but what can be done?

    Thanks
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3662

    #2
    AbbasBD,

    I would use a LEFT JOIN Query, which lists all records from [tBuy Invoice], whether there is amatching record in [tBuys] or not. Then, set the criteria for [tBuys].[BuyInvcID] Is Null, to only return the records that don't have a corresponding record in [tBuys]

    Code:
    DELETE [tBuy Invoice].*, tBuys.BuyInvcID
    FROM [tBuy Invoice] 
    LEFT JOIN tBuys 
    ON [tBuy Invoice].BuyInvcID = tBuys.BuyInvcID
    WHERE tBuys.BuyInvcID Is Null;
    Hope this helps!

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      I have no idea what this means:
      'Is Null' do not return 'no entry list'
      What is a 'no entry list'? You need to define the terms that you're using.

      Comment

      • AbbasBD
        New Member
        • Aug 2010
        • 11

        #4
        twinnyfo

        exact solution!

        thanks

        Comment

        • AbbasBD
          New Member
          • Aug 2010
          • 11

          #5
          Rabbit

          For 'no entry list' I meant tBuys has no record corresponding to specific entry in [tBuy Invoice].

          Thanks for your reply.

          Comment

          Working...