CJCoding With Joseph
15free / daySign inCreate account

Toronto or Ottawa but Not Graduated

Return first_name, last_name, city and status for students who live in Toronto or Ottawa and whose status is not graduated. Combine the two cities with OR, wrap that in parentheses, and attach the status rule with AND NOT; without the parentheses, the graduated Toronto student slips through. Sort by city, then last_name.

Expected result:

+------------+-----------+---------+--------+
| first_name | last_name | city    | status |
+------------+-----------+---------+--------+
| Charlotte  | Dubois    | Ottawa  | active |
| Grace      | Lee       | Ottawa  | active |
| Ella       | Murphy    | Ottawa  | active |
| Sophia     | Rossi     | Ottawa  | active |
| Harper     | Singh     | Ottawa  | active |
| Elijah     | Costa     | Toronto | active |
| Lucas      | Fernandes | Toronto | active |
| Scarlett   | Johnson   | Toronto | active |
| Noah       | Kim       | Toronto | active |
| Leo        | Martin    | Toronto | active |
+------------+-----------+---------+--------+
(showing 10 of 12 rows)
Hints3 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.