good afternoon All,
I would like to know the SQL to select only the "top" record of a query
sorted by date/number or operation of numbers e.g. max of date, min of
stock, etc so I only retrieve the first and most important value instead of
a set of several values.
here below an EG from a query I use every day:
SELECT pordtl.pdtiid, pordtl.pdtvds, pordtl.pdtluc, pordtl.pdtvum,
pordtl.pdtwhs, pordtl.pdtode, pordtl.pdtvdr
FROM beth.pordtl pordtl
GROUP BY pordtl.pdtiid, pordtl.pdtvds, pordtl.pdtluc, pordtl.pdtvum,
pordtl.pdtwhs, pordtl.pdtode, pordtl.pdtvdr
HAVING (pordtl.pdtiid Is Not Null)
ORDER BY pordtl.pdtode DESC
If I only need the top, or bottom, row of the order, what is the SQL
operation that narrows the query?
All information will be gratly appreciatted!
Thanks
Leo.
Nick Hodge - 01 Nov 2007 17:06 GMT
Leo
Can't test it but it should be
SELECT TOP 1.............

Signature
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
nick_hodgeTAKETHISOUT@zen.co.ukANDTHIS
web: www.nickhodge.co.uk
UK Excel User Conference In Cambridge
November 28th - December 1st 2007
Register Now @ http://www.exceluserconference.com/UKEUC.html
> good afternoon All,
>
[quoted text clipped - 21 lines]
>
> Leo.
NickName - 01 Nov 2007 21:27 GMT
top 15 will return the top 120 rows from the set or if you want the
percent
top 15 percent
goes after the word select, before the statement ie
select top 5 ....
> good afternoon All,
>
[quoted text clipped - 21 lines]
>
> Leo.