File tree Expand file tree Collapse file tree 1 file changed +15
-5
lines changed
content/sql/concepts/commands/terms/top Expand file tree Collapse file tree 1 file changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -7,8 +7,7 @@ Subjects:
7
7
Tags :
8
8
- ' Database'
9
9
- ' Queries'
10
- - ' T-SQL'
11
- - ' Transact-SQL'
10
+ - ' SQL Server'
12
11
CatalogContent :
13
12
- ' learn-sql'
14
13
- ' paths/analyze-data-with-sql'
@@ -18,21 +17,32 @@ Returns a specified number of rows from the top of the result.
18
17
19
18
## Syntax
20
19
20
+ This command is used to select the inital rows from a table, limiting the result to a specified number, represented here by (n):
21
+
21
22
``` sql
22
- SELECT TOP (10 ) column_name(s)
23
+ SELECT TOP (n ) column_name(s)
23
24
FROM table_name;
24
25
```
25
26
27
+ The command can also be used with PERCENT to limit the result to the top (n) percent of rows:
28
+
26
29
``` sql
27
- SELECT TOP (25 ) PERCENT column_name(s)
30
+ SELECT TOP (n ) PERCENT column_name(s)
28
31
FROM table_name;
29
32
```
30
33
31
- ## Example
34
+ ## Examples
32
35
33
36
The given query will display the top 5 rows from the ` books ` table.
34
37
35
38
``` sql
36
39
SELECT TOP (5 ) *
37
40
FROM books;
38
41
```
42
+
43
+ The given query will display the top 25% of rows from the ` films ` table.
44
+
45
+ ``` sql
46
+ SELECT TOP (25 ) PERCENT movie_titles
47
+ FROM movies;
48
+ ```
You can’t perform that action at this time.
0 commit comments