Click to See Complete Forum and Search --> : Syntax error


Shaolin
02-19-2009, 02:35 PM
Hi Guys

Mysql keeps telling me there is a syntax error in my query but I cannot find it. Can someone take a look and see if they can find anything wrong with the query:

DELETE FROM mail
LEFT JOIN mail_recipients ON mail_recipients.mail_id = mail.mail_id
WHERE mail.mail_id='226' AND mail.user_id='1' AND mail.is_draft='1';

criterion9
02-19-2009, 03:55 PM
What is your database structure? What error are you getting?

Shaolin
02-19-2009, 04:05 PM
MAIL RECIPIENTS TBL
mail_recipient_id, mail_id, contact_id

MAIL TBL
mail_id, user_id, title, content, is_draft

Error:
1064 (42000): You have an error in your SQL syntax. check the manual that correspends to you MySQLserver version for the right syntax to use near 'LEFT JOIN mail_recipients ON mail.mail_id=mail_recipients.mail_id WHE' at line 2

criterion9
02-19-2009, 10:16 PM
I think you might be missing the parenthesis around your ON clause:
http://dev.mysql.com/doc/refman/5.0/en/left-join-optimization.html

SELECT *
FROM a JOIN b LEFT JOIN c ON (c.key=a.key) LEFT JOIN d ON (d.key=a.key)
WHERE b.key=d.key;

chazzy
02-20-2009, 06:44 PM
what's the point of left joining on mail_recipients? are you trying to delete from both tables?