Find Products Below a Certain PriceEasy

Find Products Below a Certain Price

EasySQLPractice library · +10 XPselect and filtersqlbasic query

A small online store wants to list its cheapest products. They have a table of products.

  • products (product_id integer, product_name varchar(50), price numeric(10,2)

Return the product_name and price for all products whose price is strictly less than 50.00. The results should be ordered by price in ascending order. Ties in price should be broken by product_name in ascending order. NULL prices are not expected but should be ignored if present. An empty result set is possible if no products meet the criteria.

Tables

CREATE TABLE products (
    product_id integer PRIMARY KEY,
    product_name varchar(50) NOT NULL,
    price numeric(10,2)
);

Example data

INSERT INTO products (product_id, product_name, price)
VALUES
(1, 'Laptop', 1200.00),
(2, 'Mouse', 25.50),
(3, 'Keyboard', 75.00),
(4, 'Monitor', 300.00),
(5, 'Webcam', 45.75),
(6, 'Desk Lamp', 50.00),
(7, 'Notebook', 5.20),
(8, 'Pen', 2.00);

Your query is also checked on hidden datasets with different data.

Hints