Jump to content
Fórum Script Brasil
  • 0

(Resolvido) Problema com SELECT dentro de outro SELECT


Jordano Cherobim
 Share

Question

Quando executo o SELECT dentro do outro, retorna um valor errado, e diferente de quando eu executo apenas o SELECT de dentro.

SELECT
	(SELECT sum(C.m3) FROM carga WHERE L.idLote = 1 LIMIT 1) AS m3CARGA
FROM
     fardolamina F
INNER join
	lote L on L.idLote = F.idLote
INNER JOIN
	fornecedor O on O.idFornecedor = L.idFornecedor
INNER JOIN
	carga C on C.idLote = L.idLote
WHERE
     L.idLote = 1;

Quando executo o SELECT sozinho, ele retorna: m3CARGA = 35.00 (CORRETO)

Quando executo todo esse código ele retorna: m3CARGA = 105.00 (ERRADO)

 

Obrigado

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Tente assim:

SELECT m3CARGA
FROM fardolamina F
INNER join lote L on L.idLote = F.idLote
INNER JOIN fornecedor O on O.idFornecedor = L.idFornecedor
INNER JOIN (SELECT c1.idLote, sum(c1.m3) AS m3Carga FROM carga c1 GROUP BY c1.idLote)
 C on C.idLote = L.idLote
WHERE L.idLote = 1;

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Forum Statistics

    • Total Topics
      149.6k
    • Total Posts
      646.2k
×
×
  • Create New...