Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / November 2007

Tip: Looking for answers? Try searching our database.

database query select the "top record" only

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Leo Rod - 31 Oct 2007 22:24 GMT
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.

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.