mysql if else with a statement as its condition?
You can use dynamic sql for this purpose
The if statement chekcm if there are markups if so it tales the firwst query into a user defined variable @sql
and the executes it (see manual)
SELECT IF(EXISTS(SELECT markups.markup FROM markups)
, @sql:=' SELECT ((SELECT AVG(products.price) FROM products WHERE products.code = &quot;8G435G232AB&quot;) * (SELECT markups.markup FROM markups LIMIT 1)) + (SELECT AVG(products.price) FROM products WHERE products.code = &quot;8G435G232AB&quot;) AS code_8G435G232AB FROM products ORDER BY products.code LIMIT 1'
,@sql:='SELECT AVG(products.price) FROM products WHERE products.code = &quot;8G435G232AB&quot;');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;