title: Mysql SELECT CASE WHEN something then return field
body: <p>I have two field <em>nnmu and nnmi</em> ,</p>
  
  <pre><code>if nnmu is equal to 1, I need to return naziv_mesta from **mesto_istovara**,
  else if it's =0 I need to return naziv_mesta from mesto_utovara table
  </code></pre>
  
  <p>and reverse,</p>
  
  <pre><code>if nnmi is equal to 1, then I need  to return naziv_mesta from **mesto_utovara,** 
  else if it's =0 need to return naziv_mesta from mesto_istovara.
  </code></pre>
  
  <p>At first everything looks good, but somehow it mix up values, it work when nnmi and nnmu both are equal to 0, but when either value is 1 it returns nonsense. Any help?</p>
  
  <pre><code>select u.id_utovar,
               u.datum_isporuke,
               u.broj_otpremnice,
               r.naziv_robe,              
               CASE u.nnmu 
                WHEN u.nnmu ='0' THEN mu.naziv_mesta
                WHEN u.nnmu ='1' THEN m.naziv_mesta
               ELSE 'GRESKA'
               END as mesto_utovara,
               CASE u.nnmi
                WHEN u.nnmi = '0' THEN m.naziv_mesta 
                WHEN u.nnmi = '1' THEN mu.naziv_mesta
                ELSE 'GRESKA'
               END as mesto_istovara,                                                
               m.adresa,
               m.kontakt_osoba,
               m.br_telefona,
               u.broj_paleta,
               u.bruto,
               k.username,
               u.napomena,                  
               v.registracija,
               p.naziv_prevoznika,
               u.cena,
               u.korisnik_logistika,
               u.korisnik_analitika,
               u.datum_unosa,
               u.vreme_unosa,
               u.zakljucan,
               u.id_mesto_utovara,
               u.id_mesto_istovara,
               u.nnmu,
               u.nnmi             
        FROM utovar u ,mesto_utovara mu, mesto_istovara m, roba r, vozila v,prevoznik p, korisnik k
        WHERE u.id_mesto_istovara=m.id_mesto_istovara
         and k.id_korisnik = u.korisnik
         and r.id_robe=u.id_robe 
         and u.id_mesto_utovara = mu.id_mesto_utovara 
         and v.id_vozilo = u.id_vozilo 
         and p.id_prevoznik = u.id_prevoznik
         ORDER by u.id_utovar DESC
  </code></pre>