I have a query that looks like :
select *
from Franvaro f
inner join Anvandare a on a.id = f.anvandare_id
where (
f.friskskriven = 'Y'
and not exists (
select *
from sscpost
where franvaro_id = f.id
and friskskrivenpost = 'Y'
)
)
or (
f.startdatum <= '2020-04-05'
and not exists (
select *
from sscpost
where franvaro_id = f.id
and friskskrivenpost = 'Y'
)
)
and a.anstallningtyp = 'A'
;
I wonder if this query could be written in another way with the same output/result in order to have a better performance or better structure.I have tested also with this query(see below), but the result is not the same compared to the other query.
select *
from Franvaro f
inner join Anvandare a on a.id = f.anvandare_id
where f.friskskriven = 'Y'
or f.startdatum <= '2020-04-05'
and not exists (
select *
from sscpost
where franvaro_id = f.id
and friskskrivenpost = 'Y'
)
and a.anstallningtyp = 'A'
;