Dfox 17 Posted August 17, 2020 Report Share Posted August 17, 2020 (edited) boa noite alguém que manja em select pode me dizer se esses dois select tem o mesmo efeito, e qual melhor usar? opção 1 select codigo, codcliente, tipo_entrega, data_fechamento as data, case when NAO_CADASTRADO = 1 then nome_cliente else (select nome from c000007 Cli where Cli.codigo = OrcVen.codcliente) end as Cliente, (select nome from c000008 Vend where Vend.codigo = OrcVen.codvendedor) as Vendedor, codnf, total from c000056 OrcVen Where data_fechamento = :Pdata and OrcVen.codvenda <> '' and OrcVen.codvenda in (select Ven.codigo from c000048 Ven where Ven.data = :Pdata and Ven.codcaixa = '') opção 2 select OrcVen.codigo, OrcVen.codcliente, OrcVen.tipo_entrega, OrcVen.data_fechamento as data, case when OrcVen.NAO_CADASTRADO = 1 then OrcVen.nome_cliente else (select nome from c000007 Cli where Cli.codigo = OrcVen.codcliente) end as Cliente, (select nome from c000008 Vend where Vend.codigo = OrcVen.codvendedor) as Vendedor, OrcVen.codnf, OrcVen.total from c000056 OrcVen, c000048 Ven Where OrcVen.data_fechamento = :Pdata and OrcVen.codvenda <> '' and OrcVen.codvenda = Ven.codigo and Ven.data = :Pdata and Ven.codcaixa = '' Observação o 1 fica mais lento. Edited August 17, 2020 by Dfox . Link to post Share on other sites
Dfox 17 Posted August 17, 2020 Author Report Share Posted August 17, 2020 já compreendi a diferença , agora a pergunta é como posso fazer esse select sem esse in que deixa o select lento? select e.codigo, e.codcliente, e.total from c000056 e where e.data_fechamento = :Pdata and e.codvenda <> '' and e.codvenda in (select s.codigo from c000048 s); Link to post Share on other sites
BigWings 3,984 Posted August 17, 2020 Report Share Posted August 17, 2020 Tente usar EXISTS em vez do IN. select e.codigo, e.codcliente, e.total from c000056 e where e.data_fechamento = :Pdata and e.codvenda <> '' and EXISTS (select s.codigo from c000048 s where s.codigo = e.codvenda); BigWingsAjude o Projeto ACBr crescer - Assine o SAC Link to post Share on other sites
Dfox 17 Posted August 17, 2020 Author Report Share Posted August 17, 2020 1 hora atrás, BigWings disse: Tente usar EXISTS em vez do IN. select e.codigo, e.codcliente, e.total from c000056 e where e.data_fechamento = :Pdata and e.codvenda <> '' and EXISTS (select s.codigo from c000048 s where s.codigo = e.codvenda); testei no IBExpert ficou mais lento ainda. Link to post Share on other sites
Juliomar Marchetti 3,845 Posted August 17, 2020 Report Share Posted August 17, 2020 Que versão do Firebird está rodando? o servidor dele tu colocou em x64 suas tabelas tem indices, lembre-se indice de campo único somente se for a PK que já tem os demais sempre faça indice composto também campos texto muito grande vai afetar senão precisa remova ou tire da tabela isolando em uma única Juliomar Marchetti Ajude o Projeto ACBr crescer - Assine o SAC skype: juliomar telegram: juliomar http://www.juliomarmarchetti.com.br Projeto ACBr - A maior comunidade Open Source de Automação Comercial do Brasil Link to post Share on other sites
EMBarbosa 3,373 Posted August 18, 2020 Report Share Posted August 18, 2020 Em 17/08/2020 at 13:31, Dfox disse: já compreendi a diferença , agora a pergunta é como posso fazer esse select sem esse in que deixa o select lento? select e.codigo, e.codcliente, e.total from c000056 e where e.data_fechamento = :Pdata and e.codvenda <> '' and e.codvenda in (select s.codigo from c000048 s); poste o "plan" das querys Além disso, qual versão do Firebird? []'s Elton Ajude o Projeto ACBr crescer - Assine o SAC (15) 2105-0750 (15)99790-2976. Um engenheiro de Controle de Qualidade(QA) entra num bar. Pede uma cerveja. Pede zero cervejas. Pede 99999999 cervejas. Pede -1 cervejas. Pede um jacaré. Pede asdfdhklçkh. Link to post Share on other sites
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now