IF Statement
Posted: Wed Mar 23, 2005 1:14 am
Need to use pure SQL (MySQL) statements for these - No PHP involved because this needs to be portable on other languages - with common MySQL db.
What Im trying to do is : If Cat2 doesnt exist in the Category table then add it.
My IF statement doesnt seem to be working.
IF (SELECT * FROM Category WHERE Name='Cat1') THEN SELECT 'a';
is showing error.
The doc http://dev.mysql.com/doc/mysql/en/if-statement.html has no examples.
Any idea to fix this ?
Thanks
Code: Select all
IF (SELECT Category,Name FROM Category WHERE Name='Cat2')
THEN
ELSE
INSERT INTO Category VALUES ('','Cat2');My IF statement doesnt seem to be working.
IF (SELECT * FROM Category WHERE Name='Cat1') THEN SELECT 'a';
is showing error.
The doc http://dev.mysql.com/doc/mysql/en/if-statement.html has no examples.
Any idea to fix this ?
Thanks