Click here to Skip to main content
15,792,397 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table with the file location of images and their sizes as fields. I want to return the fiel location field of the largest image. Using MAX(fieldsize) gets me the right record, but how do I return a different field?

SELECT MAX(fldItemSize) FROM tblItemImagePaths
    WHERE fldSupplierID = @SupplierID
    AND fldSupplierCode = @SupplierCode

when I include the requried field, the query then returns two lines of data. Yes, I'm new to this :)

SELECT        MAX(fldItemSize) AS Expr1, fldItemPath
FROM            tblItemImagePaths
WHERE        (fldSupplierID = @SupplierID) AND (fldSupplierCode = @SupplierCode)
GROUP BY fldItemPath

1 solution

select top 1 myfield from tblItemImagePaths where ... ORDER BY fldItemSize DESC

is one obvious way to go.

select myfield from tblITemImagePaths where .... AND fldItemSize = MAX(fldItemSize)

is another.
Share this answer
Stu Baby 13-Aug-12 16:45pm    
Thanks Christain, most appreciated.
Christian Graus 13-Aug-12 16:51pm    
No worries, thanks for taking the time to thank me :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900