I'm using the following query:
select a.idclientecrm, max(c.falta) from clientescrmporlistadeclientescrm a
inner join clientescrmporlistadeclientescrm b on (a.idclientecrm=b.idclientecrm and a.idlistadeclientescrm = 58)
inner join tareas c on a.idclientecrm=c.idclientecrm
where b.idlistadeclientescrm = 70
But I'm not getting the result I want. I know I'm doing something wrong but I don't know what.
I want the outcome of the first inner join (aprox 22k rows) but I need to join the result to the "tareas" table and get the max date from there.
I want to use max because for every idclientecrm , there's more than one row that matches in the "tareas" table and I need the last recorded result.
If I left out something let me know.
Thnx in advance!
You probably want to move the "58" condition to the WHERE clause and group on a.idclientecrm:
select a.idclientecrm, max(c.falta)
from clientescrmporlistadeclientescrm a
inner join clientescrmporlistadeclientescrm b
on a.idclientecrm = b.idclientecrm
inner join tareas c
on a.idclientecrm = c.idclientecrm
where b.idlistadeclientescrm = 70
and a.idlistadeclientescrm = 58
group by a.idclientecrm
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.