-1
I created a query with the following objective: Select all the tools which the inventories theirs nay are gifts in all businesses. One Tool has one or more stocks, a stockpile belongs to only one enterprise.
I need to know if there is any way to do this query to avoid this code redundancy, I don’t know if I’m having a bad day so I couldn’t do better but what came out was this:
select * from ferramenta f
where f.obrigatorio = 1 and (f.codigo not in (select ferramenta_codigo
from estoque
where empresa_codigo = 2)
or f.codigo not in (select ferramenta_codigo
from estoque
where empresa_codigo = 3)
or f.codigo not in (select ferramenta_codigo
from estoque
where empresa_codigo = 4)
or f.codigo not in (select ferramenta_codigo
from estoque
where empresa_codigo = 5)
or f.codigo not in (select ferramenta_codigo
from estoque
where empresa_codigo = 6))
order by f.codigo desc
There are only companies 2,3,4,5,6.
I see no need to use all these OR operators. Just pass the ID listing with an IN condition in the stock table query.
– Confundir
Postgresql and oracle tags have been added, which effectively is the database used?
– Confundir
If I add "in" it will look for anyone inside the "in" I need to bring everyone from the "in" or none, resulting in that code I made. I am wearing postgres
– Murilo Medeiros