Find Students with Missing Email Addresses
In a college database, student records are maintained. Some students might not have provided their email addresses.
Tables:
students(student_id, name, email, major)
Return the student_id and name of all students whose email is NULL. The results should be ordered by student_id.
If there are no students with missing email addresses, return an empty result set. Ties in student_id are not possible as it's a primary key. NULL values in the email column are explicitly handled.
Tables
CREATE TABLE students ( student_id integer PRIMARY KEY, name varchar(100) NOT NULL, email varchar(100), major varchar(100) );
Example data
INSERT INTO students (student_id, name, email, major) VALUES (1, 'Alice Smith', '[email protected]', 'Computer Science'), (2, 'Bob Johnson', NULL, 'Physics'), (3, 'Charlie Brown', '[email protected]', 'Mathematics'), (4, 'Diana Prince', NULL, 'History'), (5, 'Ethan Hunt', '[email protected]', 'Chemistry');
Your query is also checked on hidden datasets with different data.
Hints
-- Select students with no email
SELECT student_id, name
FROM students
Your query runs on the example tables shown with the problem, then on hidden datasets when you submit.
Write standard SQL. MySQL habits work too: IFNULL, IF, YEAR(), DATE_FORMAT, GROUP_CONCAT, `backticks` and LIMIT 5, 10. It runs on PostgreSQL, so integer division keeps whole numbers (5 / 2 = 2): write 5.0 / 2 for 2.5.