I want to query the results in a range of dates and perform joins. Currently my query is:
SELECT fichapagos.cantidad,
users.name as nombreRecibe,
modopagos.nombre as tipoDePago,
clientes.nombre as elCliente,
conceptopagos.concepto as elConcepto
FROM fichapagos, users,modopagos,clientes,conceptopagos
WHERE MONTH(fichapagos.created_at) = MONTH(CURRENT_DATE())
AND YEAR(fichapagos.created_at) = YEAR(CURRENT_DATE())
LEFT JOIN modopagos
ON fichapagos.tipoPago = modopagos.id
LEFT JOIN clientes
ON fichapagos.organizacionPara = clientes.id
LEFT JOIN conceptopagos
ON fichapagos.conceptoPago = conceptopagos.id
LEFT JOIN users
on fichapagos.nombreRecibe = users.id
But it throws me an error:
#1064 - Algo está equivocado en su sintax cerca 'LEFT JOIN modopagos ON fichapagos.tipoPago = modopagos.id LEFT JOIN cliente' en la linea 11
The created_at field is timestamp type, if I don't have the joins the query works. If I don't have WHERE the query works. what am I doing wrong? Thanks.
Try this statement:
We
WHERE
use it after theLEFT JOIN
.Reviewing your query you have the following drawbacks:
With this, your query would be as follows:
Try it and tell us. Greetings.