|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
Anybody know how to get the last entry in a row depending on the max number of another entry in the same table. These are the 2 tables:
class : classId className status: statusId classId ... Problem: i have a number of same classId in status table but i only want the one that 1. matches the highest statusId number and 2. matches a classId entry in the class table I can only seem to get all of the classId back in statusId that match class classId. selecting max(classId) in a subquery doesn't seem to work? Is my thinking wrong - can this be done by comparing classId in 2 tables and a subquery for the max?? It must be straightforward, but i'm stumped! anyone? |
|
#2
|
||||
|
||||
|
Code:
SELECT classId, MAX(statusId) FROM Status WITH (NOLOCK) GROUP BY classId
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month |
|
#3
|
|||
|
|||
|
Works great, thanks for that.
|
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > select max |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|