MySQL WHERE Clause

The WHERE clause filters the rows. Only the rows where the condition is true are returned.

SELECT * FROM students WHERE marks > 80;
Result
id name city marks course_id
1 Robin Delhi 85 1
2 Maria Mumbai 92 2
4 Asha Jaipur 88 3

SELECT name, city FROM students WHERE city = 'Delhi';
Result
name city
Robin Delhi
Vikram Delhi

Text values are written in single quotes. Numbers are not.


Comparison operators

OperatorMeaning
=Equal
<> or !=Not equal
>, <Greater than, less than
>=, <=Greater or equal, less or equal
BETWEENIn a range
LIKEMatches a pattern
INMatches any value of a list
IS NULLHas no value
SELECT name, marks FROM students WHERE marks <= 65;
Result
name marks
Vikram 65
Neha 45


WHERE with UPDATE and DELETE

The same WHERE is used in UPDATE and DELETE, to choose which rows to change. It is very important there.


Summary

  • WHERE condition returns only matching rows.
  • Use quotes for text and no quotes for numbers.
  • Next: AND, OR and NOT.

Congratulations! Chapter Finished. Learn more about the similar topics:
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.