Products In Categories

EasySQLDatabaseSorting

Description

Write a SQL query to return the id and name of products whose category is either 'A' or 'B', ordered by id ascending. **Output columns (in order):** id, name

Table:products
ColumnType
idINT
nameTEXT
categoryTEXT

Examples

Input:CREATE TABLE products (id INT, name TEXT, category TEXT); INSERT INTO products VALUES (1,'P','A'),(2,'Q','C'),(3,'R','B');
Output:1|P 3|R
Explanation:

Products tagged with either of the two listed categories are kept and returned by id.

Input:CREATE TABLE products (id INT, name TEXT, category TEXT); INSERT INTO products VALUES (1,'A','A'),(2,'B','B'),(3,'C','A');
Output:1|A 2|B 3|C
Explanation:

Products tagged with either of the two listed categories are kept and returned by id.

Input:CREATE TABLE products (id INT, name TEXT, category TEXT); INSERT INTO products VALUES (5,'M','B'),(1,'N','A');
Output:1|N 5|M
Explanation:

Products tagged with either of the two listed categories are kept and returned by id.

Constraints

  • Use standard SQL (SQLite).

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.