Exercise: Find JavaScript Students
Write a query to find all students enrolled in the JavaScript course.
Task
Select all students where the course is 'JavaScript'.
Solution
sql
1SELECT * FROM students
2WHERE course = 'JavaScript';Expected Output
| id | name | age | course | marks | grade |
|---|---|---|---|---|---|
| 2 | Bob | 12 | JavaScript | 78 | B |
| 7 | Grace | 11 | JavaScript | 82 | B |
Understanding the Query
SELECT *- Get all columnsFROM students- From the students tableWHERE course = 'JavaScript'- Only JavaScript students
Try These Variations
sql
1-- Find Ruby students
2SELECT * FROM students WHERE course = 'Ruby';
3
4-- Find Python students
5SELECT * FROM students WHERE course = 'Python';
6
7-- Find HTML students
8SELECT * FROM students WHERE course = 'HTML';Common Errors
sql
1-- Missing quotes around string
2SELECT * FROM students WHERE course = JavaScript; -- Error!
3
4-- Wrong operator
5SELECT * FROM students WHERE course == 'JavaScript'; -- Error in SQL!Remember: SQL uses single = for comparison, not ==.
