11

I have checked the answered questions. But, solutions are not working for me.

DELETE FROM TEST2
INNER JOIN TEST1 on TEST1.FIELD2 = TEST2.FIELD2
WHERE TEST1.FIELD1 = 22;

When i execute this query, i am getting the following error in phpmyadmin.

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version 
for the right syntax to use near 'INNER JOIN TEST1 on TEST1.FIELD2 = TEST2.FIELD2' at line 2

I am getting tired. I need help. Thanks in advance.

1 Answer 1

30

This should work:

DELETE T
FROM TEST2 T
INNER JOIN TEST1 on TEST1.FIELD2 = T.FIELD2
WHERE TEST1.FIELD1 = 22;

Sample Fiddle Demo

I think you can also do it with IN:

DELETE FROM Test2
WHERE Field2 IN (
    SELECT Field2 
    FROM Test1
    WHERE Field1 = 22)
Sign up to request clarification or add additional context in comments.

2 Comments

@user2003356 -- np, glad I could help!
better to use the first one as it won't take much time to execute, instead the second one as it is correct, the first thing will happen is that the in section will be executed first and store a result then executing the primary query.

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.