Skip to content

Commit adbfdd3

Browse files
jmpos7SSwiniarskiDusch4593
authored
[New Entry] SQL Commands: SELECT TOP (#1305)
* New SQL Content * Updated SQL content, pull request syntax updates * Update content/sql/concepts/commands/terms/top/top.md * Update content/sql/concepts/commands/terms/top/top.md * Update content/sql/concepts/commands/terms/top/top.md Co-authored-by: Brandon Dusch <brandondusch@gmail.com> * Update content/sql/concepts/commands/terms/top/top.md Co-authored-by: Brandon Dusch <brandondusch@gmail.com> * Update content/sql/concepts/commands/terms/top/top.md Co-authored-by: Brandon Dusch <brandondusch@gmail.com> * Update content/sql/concepts/commands/terms/top/top.md Co-authored-by: Brandon Dusch <brandondusch@gmail.com> * Update and rename content/sql/concepts/commands/terms/top/top.md to content/sql/concepts/commands/terms/select-top/select-top.md * Update select-top.md --------- Co-authored-by: jmpos7 <jmpos7@users.noreply.github.com> Co-authored-by: SSwiniarski <86081858+SSwiniarski@users.noreply.github.com> Co-authored-by: Brandon Dusch <brandondusch@gmail.com>
1 parent d31c699 commit adbfdd3

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
```

0 commit comments

Comments
 (0)