people know that we can use if statement to configure a query in the select statement like this
select if(var=1,amount,amount/2) from mytable;
But what if I want to achieve something like this:
select amount from if(var=1,mytable1,mytable2);
Is there any way to configure the table at run time?
UPD: Here’s what MySQL
EXPLAINlooks like for the part of the query which has a condition evaluating toFALSE:Note the
Impossible WHEREpart. MySQL recognizes that the expression inWHEREis constantly evaluating toFALSE, so it doesn’t even try executing the query. Hence, no performance overhead when using this approach.