0
I have two different queries, so I have two variables with the result of each query, but I wanted to show everything in the same table, as I do in php?
$sql = "SELECT Product , SUM(Amount) AS 'Total 2017' FROM dbcentro.Registo WHERE YEAR(RegistrationDate) = YEAR(NOW()) GROUP BY Product;";
$sql1 = "SELECT Produto, CAST(Total/3 AS DECIMAL(15,1)) AS 'Média 1º Trimestre' FROM(SELECT Product AS Produto, SUM(Amount) AS Total FROM dbcentro.Registo WHERE MONTH(RegistrationDate) BETWEEN 1 AND 3 AND YEAR(RegistrationDate) = YEAR(NOW()) GROUP BY Product) Soma;";
$result = mysqli_query($conn, $sql);
$result1 = mysqli_query($conn, $sql1);
What I intended was for the Average column 1 quarter to appear here the result in the table as shown in the image below:
The first two columns are from the first query and now I want the result of the second query to appear in that column, but I still can’t get it.
I solved the problem by creating a while inside another while
Put in the answer a piece of code of how you’re doing it. Even with mistakes. So we can help you
– DNick
If both queries return the same amount of columns I believe that Union would solve, or even the same query could fetch everything, but post the code you have for each query today to make it easier for us to help.
– Otto
puts the two queries that have the same result
– 13dev
I don’t know is wrong in your code or just here but you put
$result = mysqli_query($conn, $sql);
twice (I believe that one of the two should be with the$sql1
)– rLinhares
I have no errors in the code and I don’t want to join the two queries, what I want is to show the columns I want from one query and the other in the same table
– user77403
What I intended was to notice in while how I show the product column and total 2017 of the first consultation and the column Average 1st Quarter of the second consultation within the same table that I create
– user77403
I would suggest that you supplement your question with those comments, and try to clarify a little more so that we can try to help.
– 13dev
If you decided to post the solution in the place indicated for such
– Otto