0

I had this query

DELETE c FROM review_comments AS c 
LEFT JOIN users AS u 
ON u.user_id = c.user_id
WHERE c.comment = '{$comment}'
AND u.username = '{$user}'
LIMIT 1;

It did not work until I removed LIMIT 1;

It said: 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 'LIMIT 1' at line 6

Is this the incorrect usage of LIMIT 1 in this instance? I had a same query without joining tables and LIMIT 1 worked fine?

3
  • 3
    Even if the syntax allowed it, it's questionable logic. If you want to delete a single record, you should be more specific about which record. Commented Feb 12, 2013 at 18:31
  • I think you should look into techniques for removing duplicate records, since this is what (if I understand correctly) you are essentially doing. Commented Feb 12, 2013 at 19:06
  • No my logic is not sound, it needs to be changed. I need to grab the 'comment_id', not the 'comment' AND 'user who made it'. It's a hack until I fix the bigger issue. Commented Feb 14, 2013 at 22:16

1 Answer 1

4

I don't think LIMIT can be used with multi-table referenced DELETE statements in MySQL.

Sign up to request clarification or add additional context in comments.

Comments

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.