0

Why am I getting an error with this statement?

Error: could not prepare statement (1 near "t3": syntax error)

(Note: tables renamed for simplicity)

DELETE FROM table3 t3
INNER JOIN table2 t2 ON t2.tempId = t3.tempId 
INNER JOIN table1 t1 ON t1.tempId = t2.tempId
WHERE t1.tempId = 9;
Dave
  • 5,283
  • 7
  • 44
  • 66

1 Answers1

-2

"Heh ..." I don't think that the DELETE statement knows anything about "joins" ...

... and I sure-as-heck think that I understand *why (not)."

Instead, do this:

  • Start a transaction.
  • Run a SELECT query to obtain a list of record-IDs that meet your selection criteria.
  • "Aww, heck ..." Go ahead and dump a list of those record-IDs to some log-file somewhere ....
  • Execute a series of DELETE queries to delete these IDs.
  • COMMIT. (Or, if anything-at-all goes wrong, ROLLBACK.)
Mike Robinson
  • 8,490
  • 5
  • 28
  • 41