Help With Delete Query (error)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dan2kx
    Contributor
    • Oct 2007
    • 365

    Help With Delete Query (error)

    Hello everyone,

    i have another task to complete,

    i have two tables

    Code:
    tblEvent
    -EventID - PK Auto
    -PermaID - FK Num - tblPermavent
    -Date - Date
    --other irrelevant fields
    and......
    Code:
    tblEventTemp
    -TempID - PK Auto
    -PermaID - FK Num - tblPermavent
    -Date - Date
    What i want to do is delete from tblEventTemp when a match between PermaID and Date is found, (if the record exists in tblEvent, delete from tblEventTemp)

    so far i have tried this SQL
    Code:
    DELETE tblEventTemp.* FROM tblEvent INNER JOIN tblEventTemp ON (tblEventTemp.Date = tblEvent.Date) AND (tblEvent.PermaID = tblEventTemp.PermaID);
    What i tried to do here is delete * from tblEventTemp and made two joins between the matching fields PermaID and Date.

    The query appears to work (in datasheet) however upon execution i get an error "Could not delete from specified tables"

    Any Ideas would be most welcome (to resolve my SQL), i figure this would be the easiest and most efficient way of achieving his goal, but if there are better alternatives (that work) they will be welcomes with open arms....

    thanks, Dan
  • ChipR
    Recognized Expert Top Contributor
    • Jul 2008
    • 1289

    #2
    This should work:
    Code:
    DELETE FROM tblEventTemp 
    WHERE EXISTS 
    (SELECT EventID FROM tblEvent
     WHERE tblEventTemp.PermaID = tblEvent.PermaID 
     AND tblEventTemp.Date = tblEvent.Date)
    You may want to consider renaming the "Date" field!

    Comment

    • Dan2kx
      Contributor
      • Oct 2007
      • 365

      #3
      Originally posted by ChipR
      This should work:
      Code:
      DELETE FROM tblEventTemp 
      WHERE EXISTS 
      (SELECT EventID FROM tblEvent
       WHERE tblEventTemp.PermaID = tblEvent.PermaID 
       AND tblEventTemp.Date = tblEvent.Date)
      You may want to consider renaming the "Date" field!
      Unfortunately it says "query must have at least one destination field"?

      Comment

      • ChipR
        Recognized Expert Top Contributor
        • Jul 2008
        • 1289

        #4
        Try DELETE * FROM?
        Wierd one.

        Comment

        • Dan2kx
          Contributor
          • Oct 2007
          • 365

          #5
          that works a treat!!

          thanks

          Comment

          Working...