Wherever I find an example of IF ()
function I only see something like below.
SELECT IF(500<1000, "YES", "NO");
+---------------------------+
| IF(500<1000, "YES", "NO") |
+---------------------------+
| YES |
+---------------------------+
But can I do something like below i.e executing a query?
IF(500<1000, CREATE DATABASE test1; , CREATE DATABASE test2;);
One way is to using prepared statements. But I want to directly execute the query inside it.
CASE
, not a function.IF()
function andIF..THEN..ELSE..END IF;
statements. You can call another statements from the IF statement not from the IF() function.