I have 2 selects below, how can I join in just 1 select?
I need to get everything sold in a certain period (BETWEEN) per item only at the same time I have to get what I had from the item's stock up to the start date.
To separate whether it is input or output is the option d.type
Example:
Produto Estoque qtd vendida
XPTO 100 50
Select 1:
SELECT DISTINCT d.cat_id prod, p.id, p.nome id_prod,
SUM( d.qtd ) AS qtd_prod, SUM( d.valor_total ) AS total_prod
FROM lc_controle c
INNER JOIN lc_detalhe d ON d.controle_id = c.id
INNER JOIN 'lc_cat' p ON p.id = d.cat_id
WHERE d.tipo = '0'
and c.dtConcat BETWEEN '$dtinicial' AND '$dtfinal'
and c.exportado = 'Sim'
GROUP BY d.cat_id
ORDER BY qtd_prod DESC
Select 2:
SELECT DISTINCT d.cat_id prod, p.id, p.nome id_prod,
SUM( d.qtd ) AS qtd_estoque
FROM lc_controle c
INNER JOIN lc_detalhe d ON d.controle_id = c.id
INNER JOIN 'lc_cat' p ON p.id = d.cat_id
WHERE d.tipo = '0'
and c.dtConcat < '$dtinicial'
and c.exportado = 'Sim'
GROUP BY d.cat_id
ORDER BY qtd_estoque DESC