I have 3 tables and I have the following query:
select S.ID, C.IDSENSOR, C.ID, CF.IDCANAL, MAX(CF.ENTRY_ID) as entry, cf.estado
from Sensor as S
join Canal as C on S.Id = C.IdSensor
join CanalFeed as CF on C.Id = CF.IdCanal
where S.Id = 1
GROUP BY S.ID,C.IDSENSOR,C.ID,CF.IDCANAL, cf.estado
order by CF.IDCANAL
It gives me the following result:
How would you change that query so that it brings the largest (ENTRY_ID) for each channel id? Mark in red as I only want the query to be brought to me.
Edition
How would I make it bring me only those marked in red since it would be for each channel id it brings me the largest by ENTRY
you should use
MAX(CAMPO)
for entry_id andagrupar
for the other fields test as followsWhat you can do is sort based on this Entry_Id and get its position from highest to lowest. Then it would simply be enough for you to keep the numbers 1 (the biggest)
With this you should get how you want