Alternative to using UNION in mysql/php

Asked

Viewed 278 times

0

Good morning, I am doing the sum of the elements of a column (I called Minhacoluna) in function of another, called "turn". There are three values for turn, so I need the code to return three distinct values of sum. For this, I am using the function UNION of mysql. It returns me the values without problems. However, when making the connection in PHP, the result of turn 3 is gone, only the first two values being returned. It would be the UNIONthe cause of the problem in PHP? Is there any alternative to using the same or solution for this case?

SELECT sum(MinhaColuna) as 'Soma1' from TabelaX where turno='Um' UNION 
SELECT sum(MinhaColuna) as 'Soma2' from TabelaX where turno='Dois' UNION 
SELECT sum(MinhaColuna) as 'Soma3' from TabelaX where turno='Três'
  • Tended to use the UNION ALL ? If values match, he may not be bringing.

  • I tried, yes, but the error persists.

  • 1

    Post the code of how you are generating the table... because if your select is ok, then the problem is in php

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.