From the course: Microsoft SQL Server 2019 Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Sort records - SQL Server Tutorial
From the course: Microsoft SQL Server 2019 Essential Training
Sort records
- The records that get returned in a select statement will typically appear in the order that they're stored in the database. To have them returned in a specific order that you specify, you'll add another clause to the select statement. This time it's going to be an order by clause. I'd like to review the people that we have stored in the guest table, so I'm going to come down here to the very end of our script. I'll come down a couple lines. And then we'll start a new select statement. And this time we're going to pull the guest ID, first name, last name and state columns out of the DBO.guest table. If I run this query, just these two lines here and execute that statement, we'll see the data as it's currently stored in my underlying data table. In order to sort it based off of, for instance the first name, I can simply come over here and place my cursor right after guest, but before the statement terminator. I'll just bring that down two more lines. We're going to add in an order by…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Understand the role of T-SQL1m 59s
-
(Locked)
Use the T-SQL editor6m 4s
-
(Locked)
Create a table with T-SQL5m 28s
-
(Locked)
Add data to a table3m 41s
-
(Locked)
Retrieve records with SELECT3m 28s
-
(Locked)
Filter returned results with WHERE1m 51s
-
(Locked)
Sort records2m 42s
-
(Locked)
Delete records from a table3m 32s
-
(Locked)
Update records in a table3m 4s
-
(Locked)
Join related tables5m 1s
-
(Locked)
LEFT JOIN and RIGHT JOIN2m 16s
-
(Locked)
Remove a table from the database4m 6s
-
(Locked)
-
-
-
-
-
-