|
-
Jul 14th, 2009, 06:14 AM
#1
Thread Starter
Frenzied Member
-
Jul 14th, 2009, 07:01 AM
#2
Re: [SQL Server] - Query Distinct and Max or Function
You are on the right lines - what you want isn't a Distinct or any kind of Group By, and "a kind of max for each FieldFK." is pretty much it.
The way to do that is to use a sub-query (using the same table) based on FieldFK, which you can do like this:
Code:
SELECT idReg, FieldFK, InternalNumber, Name, Qt
FROM tableName as t1
WHERE idReg = (SELECT Max(idReg)
FROM tableName
WHERE FieldFK = t1.FieldFK)
By giving the table an alias in the main query, you can refer to the values from it in the sub-query, thus causing the sub-query to run for each row of the main query (and be linked to it).
-
Jul 14th, 2009, 07:05 AM
#3
Thread Starter
Frenzied Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|