In MySQL, how to execute two different SELECT statements depending on a condition?
SELECT *
FROM ( full text of query 1 )
WHERE (condition 1)
UNION ALL
SELECT *
FROM ( full text of query 2 )
WHERE (condition 2)
  AND NOT (condition 1)


Neither condition must give NULL (due to NULL in field/variable values) in NOT.

Outer SELECTs for each separate subquery in UNION may be excess if separate queries are not complex.

For the code shown in the question it will be

SET @input1=123;
SET @input2='foobar';

SELECT @result := col12
FROM   table1
WHERE  col11 = @input1
  AND  @input1 &gt; 0

UNION ALL

SELECT @result := col21
FROM   table2
WHERE  col22=@input2
  AND  @input2 != ''
  AND  COALESCE(@input1, -1) &lt;= 0; /* prevent ejecting by NULL */