← Back to Joins
Question 1
Students and Their Majors
Students and Their Majors
List every student with the name of their major department. Return three columns:first_name,last_nameanddepartment(the department'sname, aliased). The four students who have not declared a major must still appear, withdepartmentshowing NULL. Sort bylast_name, thenfirst_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
Sign in to use hintsTopics:
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.