0

When I run this:

DELETE FROM folders AS fo
LEFT OUTER JOIN files AS fi 
ON fo.folderId = fi.folderId
WHERE fi.folderId IS NULL AND (fo.folderId IN (63,1000))

... I get a syntax error:

#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 'AS fo LEFT OUTER JOIN files AS fi ON fo.folderId = fi.folderId WHERE fi.fold' at line 1

The code is based in a SELECT query that returns the intended rows. What's the reason for the error message?

2
  • 1
    What does not work? Do you get an error? Commented Mar 15, 2013 at 11:17
  • #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 'AS fo LEFT OUTER JOIN files AS fi ON fo.folderId = fi.folderId WHERE fi.fold' at line 1 Commented Mar 15, 2013 at 11:26

2 Answers 2

1

It isn't a surprise that it "doesn't work". When I run your code I get a syntax error:

SQL Error (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 'AS fo LEFT OUTER JOIN files AS fi ON fo.folderId = fi.folderId WHERE fi.fold' at line 1

The correct syntax is:

DELETE fo -- Note I've added table name
FROM folders AS fo
LEFT OUTER JOIN files AS fi 
ON fo.folderId = fi.folderId
WHERE fi.folderId IS NULL AND (fo.folderId IN (63,1000));
Sign up to request clarification or add additional context in comments.

1 Comment

@jon I see you posted the relevant info later. I've edited the question to make it look as it should have been from the beginning.
1
DELETE
  FROM folders fo
 WHERE NOT EXISTS (SELECT 1
                     FROM files fi
                    WHERE fi.folderId = fo.folderId)
   AND fo.folderId IN (63, 1000)

3 Comments

Thanks Rachcha but the JOIN is needed so that I only delete folders that are not in the files table.
Just a min then, I'll edit my answer and give you an appropriate query for the job.
Thanks for your help Rachcha but alvaro has got thee answer..I plus oned your answer as it works, but wasn't actuauly the answer to my question... thanks again j

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.