Can IF be used to start a MySQL query?

Posted by Littledot on Stack Overflow See other posts from Stack Overflow or by Littledot
Published on 2010-12-22T07:49:31Z Indexed on 2010/12/22 7:54 UTC
Read the original article Hit count: 138

Filed under:
|

Hi there, I have a query that looks like this:

mysql_query("IF EXISTS(SELECT * FROM predict WHERE uid=$i AND bid=$j)
            THEN UPDATE predict SET predict_tfidf=$predict_tfidf WHERE uid=$i AND bid=$j
            ELSE INSERT INTO predict (uid, bid, predict_tfidf) VALUES('$i','$j','$predict_tfidf')
            END IF")or die(mysql_error());

But it dies and mysql tells me to check the syntax near IF EXISTS(....)

Can we not use an IF statement to start a mysql query?

Thank you in advance.

© Stack Overflow or respective owner

Related posts about mysql

Related posts about if-statement