CJCoding With Joseph
15free / daySign inCreate account

Students and Their Majors

List every student with the name of their major department. Return three columns: first_name, last_name and department (the department's name, aliased). The four students who have not declared a major must still appear, with department showing NULL. Sort by last_name, then first_name.

Expected result:

+------------+-----------+------------------+
| first_name | last_name | department       |
+------------+-----------+------------------+
| Henry      | Adeyemi   | Biology          |
| Oliver     | Brown     | Computer Science |
| Zoe        | Campbell  | English          |
| Elijah     | Costa     | English          |
| Charlotte  | Dubois    | Mathematics      |
| Lucas      | Fernandes | Computer Science |
| Mia        | Haddad    | English          |
| Benjamin   | Ivanov    | NULL             |
| Scarlett   | Johnson   | Fine Arts        |
| Noah       | Kim       | NULL             |
+------------+-----------+------------------+
(showing 10 of 30 rows)
Hints3 available
Topics:
Joins
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.