Help with a mysql query

1

I'm breaking my head here with a query I set up where I get the dates entered in the form and search the database.

it does the query only does not bring all the data

If I inform the start date from 01/01/2017 to today's date 15/11/17 it only brings until 10/13/2017.

If you only inform the initial date it brings all the information, if you inform only the end date it does not bring anything, so my problem is in the end date

asked by anonymous 15.11.2017 / 22:53

1 answer

2

The correct thing is for you to use BETWEEN:

$data_inicial = "2017-01-01";
$data_final = "2018-01-01";

SELECT c.dia, c.mes, c.ano, c.id id_pedido, c.total total_pedido, c.tipo, d.cat_id id_prod,
SUM( d.valor_total ) total_prod
FROM lc_controle c
INNER JOIN lc_detalhe d ON d.controle_id = c.id
WHERE data BETWEEN '".$data_inicial."' AND '".$data_final."'
AND WHERE c.tipo =  '0' 
    GROUP BY
        c.id,
        c.total,
        d.cat_id
    
15.11.2017 / 22:56