Skip
Arish's avatar

10. Practice - Not Equal Filter


Exercise: Exclude a Course

Find all students NOT enrolled in Ruby.

Task

Select all students where course is not equal to 'Ruby'.

Solution

sql
1SELECT * FROM students
2WHERE course != 'Ruby';

Or using the alternative operator:

sql
1SELECT * FROM students
2WHERE course <> 'Ruby';

Expected Output

All students except those in Ruby course.

idnamecourse
1AlicePython
2BobJavaScript
3CarolPython
.........

Practice More

sql
1-- Find students NOT in grade C
2SELECT * FROM students WHERE grade != 'C';
3
4-- Find students NOT aged 14
5SELECT * FROM students WHERE age <> 14;
6
7-- Find students with marks NOT equal to 78
8SELECT * FROM students WHERE marks != 78;

Combining Concepts

sql
1-- Select specific columns, exclude a course
2SELECT name, age, marks
3FROM students
4WHERE course != 'Python';

Summary

  • != and <> both mean "not equal"
  • Works with strings, numbers, and dates
  • NULL values need special handling (IS NULL)