title: if in a mysql query
body: <p>I was trying to do this query but I found a problem with IF statement, I also tried to insert delimiter or begin and else but it does not work the same.</p>
  
  <p>how can I project different queries depending on the value of a variable?</p>
  
  <pre><code>  create or replace view PazientiTarget as
  select P.CodFiscale
  from Paziente P INNER JOIN Esordio E ON E.Paziente=P.CodFiscale
  NATURAL JOIN Terapia T
  where E.Patologia='Ipertensione'
      and E.Cronica='si'
      and E.DataGuarigione is null
      and E.DataEsordio + interval 10 year &lt; current_date()
  group by T.Paziente,T.Farmaco
  having count(distinct T.Farmaco)&lt;=2;
  
  create or replace view Appoggio as
  select T.Farmaco,T.Patologia,count(distinct T.Paziente) as Numero
  from Terapia T NATURAL JOIN Esordio E inner join Patologia PA on PA.Nome=E.Patologia
  where T.Paziente in (select PT.CodFiscale
                       from PazientiTarget PT)
  and T.Patologia&lt;&gt;'Ipertensione'
  and PA.ParteCorpo='Cuore'
  and E.Cronica='si'
  group by T.Farmaco,T.Patologia;
  
  set @controllo=( select count(*)
               FROM Appoggio A
               where A.Numero=(select max(A1.Numero)
                             from Appoggio A1));
  
  
  if @controllo &gt; 1 then
      select*
      from Appoggio A
      limit 0;
  
  
  
  else
  
  select*
  from Appoggio A
  where A.Numero=(select max(A1.Numero)
                  from Appoggio A1
                  where A.Farmaco&lt;&gt;A1.Farmaco); 
  
  end if;
  </code></pre>