Is there a way to run the insert query in an IF statement, I know the syntax of the if
statement is
IF(condition, statement to be executed if the condition is true, statement to be executed if the condition is false)
My question is if it is possible to run an insert statement based on a condition, like
IF((Select count(*) from table where id = x) = 0, insert1, insert2)
insert1 will be a direct insert, similar to
Insert table (col1,col2..) value (val1,val2..)
insert2 will get the previous value of the id whose count is not 0, then do some logic and finally insert the query, which will look like
insert into table (col1, col2, col3..) select val1,val1 val2,someOperation from table where id = x;
I think you need something like this:
MYSQL example: