This is very weird, so I could use a pair of spare eyes to understand what's happening.
So I have this query:
WITH x as (
SELECT num_aula, tipo_aula, min(abs(capienza-1)) score
FROM aula
JOIN (
select num_aula, tipo_aula
from aula
where tipo_aula = 'Laboratorio'
minus
select num_aula, tipo_aula
from occr_lezione
where to_char(Data_inizio_occr_lezione,'hh24:mi') = '12:30'
and Nome_sede = 'Centro Direzionale'
and Giorno_lezione = 2
)
USING(num_aula,tipo_aula)
GROUP BY num_aula, tipo_aula
ORDER BY score asc
)
SELECT *
FROM x
which return this result set:
NUM TIPO_AULA SCORE
--- -------------------- ----------
1 Laboratorio 35
2 Laboratorio 35
Which is the desired result.
Now, if I add this line to the query:
WHERE rownum = 1;
which should return the first row of the table, I get this:
NUM TIPO_AULA SCORE
--- -------------------- ----------
2 Laboratorio 35
How is that possible?