CJCoding With Joseph
15free / daySign inCreate account

Everyone Outside CS and Math

Return first_name, last_name and major_department_id for every student whose major is neither Computer Science (department 1) nor Mathematics (department 2). The four students with no declared major are also outside those two departments and must appear, with NULL in the third column; NOT IN alone drops them, because NULL compared with anything is unknown rather than true. Sort by last_name, then first_name.

Expected result:

+------------+-----------+---------------------+
| first_name | last_name | major_department_id |
+------------+-----------+---------------------+
| Henry      | Adeyemi   |                   4 |
| Zoe        | Campbell  |                   3 |
| Elijah     | Costa     |                   3 |
| Mia        | Haddad    |                   3 |
| Benjamin   | Ivanov    |                NULL |
| Scarlett   | Johnson   |                   6 |
| Noah       | Kim       |                NULL |
| Abigail    | Larsen    |                   5 |
| Ella       | Murphy    |                   3 |
| Mason      | Nguyen    |                   5 |
+------------+-----------+---------------------+
(showing 10 of 17 rows)
Hints4 available
Topics:
SELECT Basics
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (sel, ins, desc)

Results

Run your SQL to see every statement's output here, then how it compares with the expected answer.

Not sure what is in a table? SHOW TABLES lists them and DESCRIBE students shows the columns — or open the database browser on the left.