I have this table and I would like to do the following :
idstep idproject beg_date end_date
1 1
2 1
3 1
4 1
1 2
2 2
3 2
4 2
5 2
1 3
2 3
3 3
Retrieve the Maximum steps for each project without using “GROUP BY”
Using the GROUP BY clause, I get the result that I want which is the following:
SELECT MAX(idstep), idproject
FROM mytable
GROUP BY idproject;
Result:
idstep idproject
4 1
5 2
3 3
Please, can anyone here can help me out with this issue?
I agree that this makes more sense to use GROUP BY for this particular case, but this should work:
And here is the Fiddle.
You could also use NOT EXISTS (feel like I’ve been using it all night), although I personally prefer the LEFT JOIN / NULL approach:
More fiddle: http://www.sqlfiddle.com/#!2/ebbc2/1
Good luck.