Lavorando con i dati della tabella del mio primo post questa query mi dà problemi:
codice:
select *,
case
when
f2 is null then 3
when f3 is null then 2
else 1
END as pertinenza
from tabella
where
name = 'test' and f1 = 13 and ((f2 = 10 and f3 = '9999') or (f2 = 10 and f3 is null) or (f2 is null and f3 is null))
order by pertinenza limit 1
Dovrebbe restituire:
codice:
2 | test | 13 | 10 | null | A | C | 2
ma invece dà zero risultati.
CREDO sia perchè non contempli il caso in cui ... and f3 not exist perchè nel secondo OR tu metti (f2 = 10 and f3 is null) ma '9999' non è null, semplicemente non esiste.
O detto in altri termini....mettendo fr = '9999', nessuna di queste tre condizioni è vera.
codice:
((f2 = 10 and f3 = '9999') or (f2 = 10 and f3 is null) or (f2 is null and f3 is null))
Mannaggia non mi riesce di spiegarmi bene ...