I don’t know if it’s the ideal solution.
I don’t know if it’s the right way either.
But for the title of curiosity and study (for me and for everyone), take a look at this Function
.
DELIMITER //
CREATE FUNCTION SimpleCompare(n INT)
RETURNS VARCHAR(500)
BEGIN
DECLARE s VARCHAR(500);
IF n <= 10 THEN insert into tabela(campo) values(FLOOR(RAND()*10)); SET s = 'INSERIDO';
ELSE select GROUP_CONCAT(campo) from tabela into s;
END IF;
RETURN s;
END //
DELIMITER ;
Calling her that:
select SimpleCompare(8);
select SimpleCompare(11);
In PHP it is a little simpler, but as no language indicated do not know if you are using any.
if($x>10){
$sql = "insert into tabela(campos) values(valores)";
}else{
$sql = "select campos from tabela";
}
Already tried to go straight to the Mysql site?: https://dev.mysql.com/doc/refman/5.5/en/if.html
– Pagotti