Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
SQL Order By | Filtering Statements
SQL Tutorial for Beginners
course content

Contenido del Curso

SQL Tutorial for Beginners

SQL Tutorial for Beginners

1. Database & Introduction to Syntax
2. SQL Aggregate Functions
3. Filtering Statements

SQL Order By

To sort your result records, use ORDER BY construction. There is a syntax of query:

12345
-- do not run this query SELECT col1, col2, ... FROM table WHERE condition ORDER BY some_col1, some_col2, ...
copy

ORDER BY is at the end of the query, and sorts by one or multiple columns in their order. For example, if there is a construction ORDER BY singer, title, the result will be sorted by singer's name, but for multiple songs of the same singer, records will be sorted by title.

By default, sorting is in ascending order, but you can define it. Use ASC and DESC keywords after each column name:

123
SELECT id, title, year FROM songs ORDER BY year DESC
copy

ASC or DESC statement relates to the column name before it. It means, that in ORDER BY title ASC, price DESC first sorts by title in ascending order, and then by price in descending order.

Tarea

Create a rating of songs from the most to the least expensive. Display title, singer, and price of these songs.

Tarea

Create a rating of songs from the most to the least expensive. Display title, singer, and price of these songs.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Sección 3. Capítulo 5
toggle bottom row

SQL Order By

To sort your result records, use ORDER BY construction. There is a syntax of query:

12345
-- do not run this query SELECT col1, col2, ... FROM table WHERE condition ORDER BY some_col1, some_col2, ...
copy

ORDER BY is at the end of the query, and sorts by one or multiple columns in their order. For example, if there is a construction ORDER BY singer, title, the result will be sorted by singer's name, but for multiple songs of the same singer, records will be sorted by title.

By default, sorting is in ascending order, but you can define it. Use ASC and DESC keywords after each column name:

123
SELECT id, title, year FROM songs ORDER BY year DESC
copy

ASC or DESC statement relates to the column name before it. It means, that in ORDER BY title ASC, price DESC first sorts by title in ascending order, and then by price in descending order.

Tarea

Create a rating of songs from the most to the least expensive. Display title, singer, and price of these songs.

Tarea

Create a rating of songs from the most to the least expensive. Display title, singer, and price of these songs.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Sección 3. Capítulo 5
toggle bottom row

SQL Order By

To sort your result records, use ORDER BY construction. There is a syntax of query:

12345
-- do not run this query SELECT col1, col2, ... FROM table WHERE condition ORDER BY some_col1, some_col2, ...
copy

ORDER BY is at the end of the query, and sorts by one or multiple columns in their order. For example, if there is a construction ORDER BY singer, title, the result will be sorted by singer's name, but for multiple songs of the same singer, records will be sorted by title.

By default, sorting is in ascending order, but you can define it. Use ASC and DESC keywords after each column name:

123
SELECT id, title, year FROM songs ORDER BY year DESC
copy

ASC or DESC statement relates to the column name before it. It means, that in ORDER BY title ASC, price DESC first sorts by title in ascending order, and then by price in descending order.

Tarea

Create a rating of songs from the most to the least expensive. Display title, singer, and price of these songs.

Tarea

Create a rating of songs from the most to the least expensive. Display title, singer, and price of these songs.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

To sort your result records, use ORDER BY construction. There is a syntax of query:

12345
-- do not run this query SELECT col1, col2, ... FROM table WHERE condition ORDER BY some_col1, some_col2, ...
copy

ORDER BY is at the end of the query, and sorts by one or multiple columns in their order. For example, if there is a construction ORDER BY singer, title, the result will be sorted by singer's name, but for multiple songs of the same singer, records will be sorted by title.

By default, sorting is in ascending order, but you can define it. Use ASC and DESC keywords after each column name:

123
SELECT id, title, year FROM songs ORDER BY year DESC
copy

ASC or DESC statement relates to the column name before it. It means, that in ORDER BY title ASC, price DESC first sorts by title in ascending order, and then by price in descending order.

Tarea

Create a rating of songs from the most to the least expensive. Display title, singer, and price of these songs.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
Sección 3. Capítulo 5
Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
We're sorry to hear that something went wrong. What happened?
some-alt