的Postgres 8.4
DELETE
FROM processing_transaction AS pt
INNER JOIN processing_transaction_movement AS ptm
ON pt.processing_transaction_id = ptm.processing_transaction_id
LEFT OUTER JOIN test_package tesp ON pt.test_package_id = tesp.test_package_id
LEFT OUTER JOIN test_batch tbat On tesp.test_batch_id = tbat.test_batch_id
WHERE pt.processing_transaction_type = 'TEST';
我獲得以下錯誤:錯誤的PostgreSQL有內刪除JOIN
ERROR: syntax error at >>INNER<< LINE 1: DELETE FROM processing_transaction AS pt INNER JOIN processi...
請你能幫我找到我的SQL查詢錯誤
感謝您的支持@desislavkamenov @jan。 現在我用這個:
BEGIN WORK;
DELETE FROM processing_transaction AS pt USING processing_transaction_movement AS ptm, test_package tesp, test_batch tbat WHERE pt.processing_transaction_type = 'TEST'; AND pt.processing_transaction_id = ptm.processing_transaction_id AND pt.test_package_id = tesp.test_package_id AND tesp.test_batch_id = tbat.test_batch_id
ROLLBACK;
但我需要從兩個表(processing_transaction和processing_transaction_movement)刪除數據,我都在尋找這樣的somethink並且發現了我可以做到這一點「ON DELETE CASCADE 」。但我不知道如何在這裏使用它。 所以請再次幫助我。
嗯......你的'delete'語句是荒謬的,因爲你還沒有指定你想刪除行的表。 – 2012-11-13 16:47:43
我不知道postgres,但是在SQl Server中,您應該在刪除單詞後爲您要刪除的表放置別名。它不知道從哪個表中刪除。 – HLGEM
如果您從主表中刪除其他表時有外鍵,它將自動級聯和刪除記錄。 –