Even-Id Items

EasySQLDatabaseSorting

Description

Write a SQL query to return the id and name of items whose id is even, ordered by id ascending. **Output columns (in order):** id, name

Table:items
ColumnType
idINT
nameTEXT

Examples

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

Keeping rows whose id divides evenly by two returns the even-numbered items by id.

Input:CREATE TABLE items (id INT, name TEXT); INSERT INTO items VALUES (2,'P'),(4,'Q'),(6,'R');
Output:2|P 4|Q 6|R
Explanation:

Keeping rows whose id divides evenly by two returns the even-numbered items by id.

Input:CREATE TABLE items (id INT, name TEXT); INSERT INTO items VALUES (10,'M'),(7,'N');
Output:10|M
Explanation:

Keeping rows whose id divides evenly by two returns the even-numbered items by id.

Constraints

  • Use standard SQL (SQLite).

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.