database query select the "top record" only

  • Thread starter Thread starter Leo Rod
  • Start date Start date
L

Leo Rod

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.
 
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 ....
 
Back
Top