Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Sorting by multiple columns | Sorting
SQL Basics
course content

Зміст курсу

SQL Basics

SQL Basics

1. Selecting
2. Filtering
3. Aggregating
4. Sorting
5. Grouping
6. Practicing

bookSorting by multiple columns

Can we sort by multiple columns at once? And what does it mean? Assume, we firstly sort by one column. If there are some matches in this column, then sorting by another column will sort within this sub-group.

To make SQL sort by multiple columns at once just write ORDER BY followed by column names you want to sort by separated with a comma. For example, we can sort the entire audi_cars table firstly by engine size (enginesize) in descending order and then by price in ascending.

123
SELECT * FROM audi_cars ORDER BY enginesize DESC, price
copy
Завдання
test

Swipe to show code editor

Sort audi_cars table by mileage in ascending order and then by price in descending order.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 4. Розділ 4
toggle bottom row

bookSorting by multiple columns

Can we sort by multiple columns at once? And what does it mean? Assume, we firstly sort by one column. If there are some matches in this column, then sorting by another column will sort within this sub-group.

To make SQL sort by multiple columns at once just write ORDER BY followed by column names you want to sort by separated with a comma. For example, we can sort the entire audi_cars table firstly by engine size (enginesize) in descending order and then by price in ascending.

123
SELECT * FROM audi_cars ORDER BY enginesize DESC, price
copy
Завдання
test

Swipe to show code editor

Sort audi_cars table by mileage in ascending order and then by price in descending order.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 4. Розділ 4
toggle bottom row

bookSorting by multiple columns

Can we sort by multiple columns at once? And what does it mean? Assume, we firstly sort by one column. If there are some matches in this column, then sorting by another column will sort within this sub-group.

To make SQL sort by multiple columns at once just write ORDER BY followed by column names you want to sort by separated with a comma. For example, we can sort the entire audi_cars table firstly by engine size (enginesize) in descending order and then by price in ascending.

123
SELECT * FROM audi_cars ORDER BY enginesize DESC, price
copy
Завдання
test

Swipe to show code editor

Sort audi_cars table by mileage in ascending order and then by price in descending order.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Can we sort by multiple columns at once? And what does it mean? Assume, we firstly sort by one column. If there are some matches in this column, then sorting by another column will sort within this sub-group.

To make SQL sort by multiple columns at once just write ORDER BY followed by column names you want to sort by separated with a comma. For example, we can sort the entire audi_cars table firstly by engine size (enginesize) in descending order and then by price in ascending.

123
SELECT * FROM audi_cars ORDER BY enginesize DESC, price
copy
Завдання
test

Swipe to show code editor

Sort audi_cars table by mileage in ascending order and then by price in descending order.

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 4. Розділ 4
Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt