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

Sort records - SQL Server Tutorial

From the course: Microsoft SQL Server 2019 Essential Training

Start my 1-month free trial

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…

Contents