I have a database with two tables as follow :
Where I want to get the latest Log for each user as :
I can get the result by the query (Q1) :
select u.login, tempLogs.createdDate from User as u,
(select * from Logs as n1 order by n1.createdDate desc ) as tempLogs
where tempLogs.userId = u.id
group by u.login;
But this one (Q2) doesn't work:
select tempCK.login, tempCK.createdDate from
(select u.login as login, n1.createdDate as createdDate from Logs as n1 , User as u
where n1.userId = u.id
order by n1.createdDate desc
) as tempCK
group by tempCK.login
I expected the result of inner select in Q2 to be ordered and the Q2 group by to take first of each result so the Q2 would be equivalent to Q1 !
Can someone help me to get the difference ?