I have a query like this:
IF EXISTS(SELECT 1 FROM table1 WHERE col1 = ? LIMIT 1) THEN
DELETE FROM table2 WHERE col2 = ?
END IF
But I don't know why above query does not work. Also this does not work too:
IF  EXISTS(SELECT 1 FROM table1 WHERE col1 = ? LIMIT 1) BEGIN
DELETE FROM table2 WHERE col2 = ?
END
MySQL tell my there is a syntax error, How can I fix it?
IFstatements outside of a procedure. The documentation does state this. If you were to actually read it, you may also find the answer to your question. Is there some reason you were unable to read the documentation?IFin your application logic.IFin mysql! anyway ok thanks.