File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed
content/sql/concepts/commands/terms/select-top Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ Title : ' SELECT TOP'
3
+ Description : ' Returns a specified number of rows from the top of the result.'
4
+ Subjects :
5
+ - ' Data Science'
6
+ - ' Computer Science'
7
+ Tags :
8
+ - ' Database'
9
+ - ' Queries'
10
+ - ' SQL Server'
11
+ CatalogContent :
12
+ - ' learn-sql'
13
+ - ' paths/analyze-data-with-sql'
14
+ ---
15
+
16
+ The ** ` SELECT TOP ` ** command returns a specified number of rows from the top of the result.
17
+
18
+ ## Syntax
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
+
22
+ ``` sql
23
+ SELECT TOP (n) column_name(s)
24
+ FROM table_name;
25
+ ```
26
+
27
+ Where ` column_name(s) ` is a comma delimited list of columns from the table ` table_name ` .
28
+
29
+ The command can also be used with ` PERCENT ` to limit the result to the top ` n ` percent of rows:
30
+
31
+ ``` pseudo
32
+ SELECT TOP (n) PERCENT column_name(s)
33
+ FROM table_name;
34
+ ```
35
+
36
+ ## Examples
37
+
38
+ The following query selects all columns from the top 5 rows of the ` books ` table:
39
+
40
+ ``` sql
41
+ SELECT TOP (5 ) *
42
+ FROM books;
43
+ ```
44
+
45
+ The next query selects the top 25% of rows from the ` movies ` table, under just the ` movie_titles ` column:
46
+
47
+ ``` sql
48
+ SELECT TOP (25 ) PERCENT movie_titles
49
+ FROM movies;
50
+ ```
You can’t perform that action at this time.
0 commit comments