Contacts With Email

EasySQLDatabaseSorting

Description

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

Table:contacts
ColumnType
idINT
nameTEXT
emailTEXT

Examples

Input:CREATE TABLE contacts (id INT, name TEXT, email TEXT); INSERT INTO contacts VALUES (1,'A','a@x.com'),(2,'B',NULL),(3,'C','c@x.com');
Output:1|A 3|C
Explanation:

Rows missing an email are excluded, leaving the contacts that have one, ordered by id.

Input:CREATE TABLE contacts (id INT, name TEXT, email TEXT); INSERT INTO contacts VALUES (1,'A','x'),(2,'B','y');
Output:1|A 2|B
Explanation:

Rows missing an email are excluded, leaving the contacts that have one, ordered by id.

Input:CREATE TABLE contacts (id INT, name TEXT, email TEXT); INSERT INTO contacts VALUES (2,'P',NULL),(1,'Q','q@x');
Output:1|Q
Explanation:

Rows missing an email are excluded, leaving the contacts that have one, ordered by id.

Constraints

  • Use standard SQL (SQLite).

Ready to solve this problem?

Practice solo and sharpen your skills for technical interviews.