SQL SELECT TOP Statement

In SQL how do I limit the number of records returned?

  • The SELECT TOP statement returns a specified number of records.
  • SELECT TOP is useful when working with very large datasets.
  • Non SQL Server databases use keywords like LIMIT, OFFSET, and ROWNUM.

The SQL SELECT TOP syntax

The general syntax is

SELECT TOP n column-names
  FROM table-name

SQL SELECT TOP

Problem: List the top 10 most expensive products
ordered by price
SELECT TOP 10 Id, ProductName, UnitPrice, Package
  FROM Product
 ORDER BY UnitPrice DESC
Result:  10 records.
Id ProductName UnitPrice Package
38 Côte de Blaye 263.50 12 - 75 cl bottles
29 Thüringer Rostbratwurst 123.79 50 bags x 30 sausgs.
9 Mishi Kobe Niku 97.00 18 - 500 g pkgs.
20 Sir Rodney's Marmalade 81.00 30 gift boxes
18 Carnarvon Tigers 62.50 16 kg pkg.
59 Raclette Courdavault 55.00 5 kg pkg.
51 Manjimup Dried Apples 53.00 50 - 300 g pkgs.
62 Tarte au sucre 49.30 48 pies
43 Ipoh Coffee 46.00 16 - 500 g tins
28 Rössle Sauerkraut 45.60 25 - 825 g cans


Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Licensing       EULA       Sitemap      
© Data & Object Factory, LLC.
Made with    in Austin, Texas