MySQL WHERE Clause

ย MySQL WHERE Clause

The WHERE clause in MySQL is used to filter records from a table based on a specific condition. It helps retrieve only those rows that match the criteria defined in the query.


๐Ÿ“Œ Basic Syntax


 


๐Ÿงช Example Table

Assume we have a table named employees:

id name department salary
1 Raj HR 30000
2 Priya IT 50000
3 Aman Sales 40000
4 Neha IT 55000

โœ… Example Queries

1๏ธโƒฃ Selecting rows based on a number condition:



 

Result:

name salary
Priya 50000
Neha 55000

2๏ธโƒฃ Filter using a text value:



 


3๏ธโƒฃ Using NOT operator:


 


โš™ Comparison Operators used with WHERE

Operator Meaning Example
= Equal salary = 30000
<> or != Not equal salary <> 40000
> Greater than salary > 50000
< Less than salary < 25000
>= Greater than or equal salary >= 30000
<= Less than or equal salary <= 45000

๐Ÿ” Logical Operators

AND โ€” Both conditions must be true



 


OR โ€” At least one condition must be true



 


BETWEEN โ€” Range condition



 


IN โ€” Match multiple values



 


LIKE โ€” Pattern matching (used for text)

Pattern Meaning
% Zero or more characters
_ One character

Examples:



 


๐Ÿ“Œ Using WHERE with ORDER BY & LIMIT



 


๐Ÿ Summary

Feature Example
Filter numeric values WHERE salary > 40000
Filter text WHERE department = 'IT'
Use multiple conditions AND, OR, NOT
Range check BETWEEN 30000 AND 60000
Match specific values IN ('IT', 'Sales')
Pattern search LIKE '%abc%'

โœ” The WHERE clause helps retrieve exactly the data you need โ€” not the entire table.

CodeCapsule

Sanjit Sinha โ€” Web Developer | PHP โ€ข Laravel โ€ข CodeIgniter โ€ข MySQL โ€ข Bootstrap Founder, CodeCapsule โ€” Student projects & practical coding guides. Email: info@codecapsule.in โ€ข Website: CodeCapsule.in

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *