Ever Enrolled
Easysql
Learn the Concept: UNIONWrite a query returning every distinct student_id who was enrolled in 2025, 2026, or both, ordered ascending.
sqlCREATE TABLE enrolled_2025 (student_id INTEGER NOT NULL); CREATE TABLE enrolled_2026 (student_id INTEGER NOT NULL);
Sample data:
sqlINSERT INTO enrolled_2025 (student_id) VALUES (1), (2), (3), (4); INSERT INTO enrolled_2026 (student_id) VALUES (2), (3), (5);
Example 1
Input
(none)
Output
student_id 1 2 3 4 5
UNION combines both years and removes duplicate student ids. Reference: SELECT student_id FROM enrolled_2025 UNION SELECT student_id FROM enrolled_2026 ORDER BY student_id;
Related Problems
- Engineering Team by SalaryEasy · sqlSolve Problem
- Employees Without a ManagerEasy · sqlSolve Problem
- Duplicate EmailsEasy · sqlSolve Problem