Answer the question
In order to leave comments, you need to log in
How to take join method from user variable?
The task is to change the type of the join depending on some condition.
Set a variable according to some condition:
set @type = (SELECT CASE WHEN (подзапрос) = 0
THEN 'left'
ELSE 'inner'
END)
@type JOIN table ON ...
Answer the question
In order to leave comments, you need to log in
Do always left join
and write in where for inner join
select a.*, b.*
from table1 a
left join table2 b on (a.id = b.id)
where 1=1 /*постоянное*/
and b.id is not null /*при наличии этой строки будет inner join для left join*/
IF (подзапрос) = 0
SELECT … LEFT JOIN
ELSE
SELECT … INNER JOIN
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question