AdBlock Detected!
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.
SQL TOP |
SQL > Advanced SQL >
Top
The TOP keyword restricts the number of results returned from a SQL statement in Microsoft SQL Server. SyntaxThe syntax for TOP is as follows: SELECT TOP [TOP argument] "column_name"
FROM "table_name"; where [TOP argument] can be one of two possible types: 1. [N]: The first N records are returned. 2. [M] PERCENT: The number of records corresponding to M% of all qualifying records are returned. ExamplesWe use the following table for our examples. Table Store_Information
Example 1: [TOP argument] is an integerTo show the two highest sales amounts in Table Store_Information, we key in, SELECT TOP 2 Store_Name, Sales, Txn_Date
FROM Store_Information ORDER BY Sales DESC; Result:
Example 2: [TOP argument] is a percentageTo show the top 25% of sales amounts from Table Store_Information, we key in, SELECT TOP 25 PERCENT Store_Name, Sales, Txn_Date
FROM Store_Information ORDER BY Sales DESC; Result:
|
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.