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| Column | Type |
|---|---|
| id | INT |
| name | TEXT |
| category | TEXT |
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|RExplanation:
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|CExplanation:
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|MExplanation:
Products tagged with either of the two listed categories are kept and returned by id.
Constraints
- •
Use standard SQL (SQLite).