set @var = (
select
case
when
t1.field is not null
then
t1.field
else
one
end as field_name
from
table1 t1
join table2 t2 on t1.tid = t2.id
where
t1.field2 = '_UNEXISTING_IN_DB_VALUE_'
order by t1.tid desc
limit 1
); set @ var2 = (select if (@var is null, 1, @ var));
set @var = (
select
case
when
count (1)> 0
then
t1.field
else
one
end as field_name
from
table1 t1
join table2 t2 on t1.tid = t2.id
where
t1.field2 = '_UNEXISTING_IN_DB_VALUE_'
order by t1.tid desc
limit 1
); Source: https://habr.com/ru/post/105525/
All Articles