Tiny Deathstars of Foulness

No, SQL top doesn’t look at the status of a database the way the TOP command in bash does. It looks at the top number of records returned in a query, so a bit more like head. This makes SELECT TOP useful with larger tables where this will be millions of records getting loaded into memory during a query.

In this article, we’ll use the same “Customers” table from our first articles to test out TOP:

ID Site Contact Address City Zip Country
1 Krypted Charles Edge my house Minneapolis 55418 US
2 Apple Tim Cook spaceship Cupertino 95014 US
3 Microsoft Satya Nadella campus Redmond 98053 US
4 Facebook Mark Zuckerberg foodhall Menlo Park 94025 US
5 JAMF Dean Hager Grain Exchange Minneapolis 55418 US

The following SELECT TOP statement shows the top 20% of the records from “Customers”:


Or just SELECT TOP the first three records:

SELECT TOP 3 * FROM Customers;


February 23rd, 2016

Posted In: SQL

Tags: , , , ,