From the course: Introduction to SQL Using Google BigQuery

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

ORDER BY clause

ORDER BY clause

- [Instructor] We can learn a lot from our data by simply sorting it in a particular order. The ORDER BY clause allows us to do this with BigQuery. For this example, let's say we wanted to look at the product_id, product_name, and retail_price columns from the product table. This simple SELECT statement should work. But what if we wanted to order our products using the retail price? If we wanted to sort our products from least to most expensive using the retail_price column, we can add an ORDER BY clause at the end of our query. This is shown here with the ORDER BY retail_price, following the line with the FROM wisdom_pets.products. By default, when we use ORDER BY, it will sort columns or expressions from smallest to largest, also known as ascending order. This behavior can be explicitly coded in BigQuery by using ASC after the retail_price column input in the ORDER BY clause. If instead, we wanted to sort our output…

Contents