Skip to content

Tag: greatest-n-per-group

Select row with most recent date per user

I have a table (“lms_attendance”) of users’ check-in and out times that looks like this: I’m trying to create a view of this table that would output only the most recent record per user id, while giving me the “in” or “out” value, so something like: I’m pr…

Select EMP with max SAL from each DEPT

I´m having a bad time with a SQL query. I´m using oracle default tables: ‘EMP’ TABLE http://imageshack.us/photo/my-images/850/sinttuloxps.png/ AND ‘DEPT’ TABLE http://imageshack.us/photo/my-images/19/assayp.png/ I wan´t to get the employee with the highest salary in each department. I´…

how to sort order of LEFT JOIN in SQL query?

OK I tried googling for an answer like crazy, but I couldn’t resolve this, so I hope someone will be able to help. Let’s say I have a table of users, very simple table: and I have another table of their cars and their prices. Now what I need to do is something like this (feel free to rewrite): Whi…