CodeBlanks Logo Icon CodeBlanks

Customer query

Write a filtered and ordered query on the customer table.

Challenge 1: Write a query

In this challenge you will write a query combining SELECT, WHERE and ORDER BY. Few hints; use what you learned.

SELECT name, price FROM products WHERE price > 10 ORDER BY price DESC;

This query sorts products over 10 by price descending.

name, price is selected from products. WHERE keeps only the rows where price > 10 holds. The result is sorted by price in descending order.

Practice Challenge 1: Write a query

Select name and price from products where price > 10, ordered by price descending.

Starter code

query.sql
-- challenge
SELECT name, price
FROM products
WHERE
ORDER BY

Sample solution

query.sql
SELECT name, price
FROM products
WHERE price > 10
ORDER BY price DESC

Expected output

name   price
Çanta  25
Defter 12

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What is the order of SELECT, WHERE, ORDER BY?

  • SELECT ORDER BY WHERE
  • WHERE SELECT ORDER BY
  • SELECT FROM WHERE ORDER BY Correct answer
  • ORDER BY WHERE SELECT

Explanation: Order: SELECT, FROM, WHERE, ORDER BY.

2 Customer query: match the terms

Term Meaning
SELECT columns
WHERE filter
ORDER BY sort
DESC descending

All lessons in Beginner