0

I am facing error in my query while deleting row from two table which have same primary and foreign key : Query:

DELETE FROM TABLE1 INNER JOIN TABLE2 ON (TABLE1.id=TABLE2.id) WHERE TABLE1.id='21306';

ERROR: syntax error at or near "INNER"

Using rdbms POSTGRESQL

3
  • Unrelated to your problem, but: Postgres 9.3 and 9.5 are no longer supported you should plan an upgrade as soon as possible. Commented Nov 22, 2021 at 17:11
  • Just as expected. Do WHERE EXISTS instead. Commented Nov 22, 2021 at 17:12
  • That syntax simply isn't correct. See the manual for the correct syntax. Commented Nov 22, 2021 at 17:12

1 Answer 1

1

You can't have a join in the from clause of a delete in Postgresql (although this is supported in SQL Server). Any additional table that you want to participate in the delete must be added to the using clause. Try this instead:

DELETE FROM TABLE1
 USING TABLE2 
 WHERE (TABLE1.id=TABLE2.id) AND TABLE1.id='21306';
Sign up to request clarification or add additional context in comments.

10 Comments

I want to delete record from both the tables
You can only delete from one table using one delete statement. You can delete from multiple tables in a single SQL statement using a WITH statement
@Dungeonwolf: then you need to run two DELETE statements.
is it possible to delete record from both table using a single query?
can i get a query using with statement?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.