mysql error: each derived table must have its own alias

1

I am trying to join two tables questionario and resposta and select from the table questionario two dates, this was the code I tried in php:

$verificar=mysqli_query($link,"SELECT questionario.*, resposta.* from questionario 
JOIN resposta on questionario.pergunta_id=resposta.pergunta_id,
(select COUNT(pergunta_id) as total, classificacao from questionario 
where data BETWEEN '".$_POST["datainicial"]."' AND '".$_POST["datafinal"]."' 
group by classificacao");
        while ($linha = mysqli_fetch_assoc($verificar)) {...}

But it returns this error:

  

Warning: mysqli_fetch_assoc () expects parameter 1 to be mysqli_result, boolean given

I've reviewed the internet, and I can not find a solution.

So I tried the following in phpMyAdmin:

SELECT questionario.*, resposta.* from questionario 
JOIN resposta on questionario.pergunta_id=resposta.pergunta_id,
     (select COUNT(pergunta_id) AS total, classificacao from questionario where data 
BETWEEN '2018/06/07' AND '2018/06/08' GROUP by classificacao)

As expected the query did not work, it returns this error

  

Each derived table must have its own alias ...

Here is the structure of the tables


Examples of some data entered in the tables Home Questionnaire table

asked by anonymous 08.06.2018 / 17:09

1 answer

1

Ana, use this query below:

Select COUNT(questionario.pergunta_id) total,questionario.*, resposta.* from 
questionario 
JOIN resposta on questionario.pergunta_id = resposta.pergunta_id
Where questionario.data BETWEEN '2018-06-07' AND '2018-06-08'
group by questionario.pergunta_id

Response to PHP error: MySQL Error "expects parameter 1 to be resource, boolean given in "

    
08.06.2018 / 17:36