SQL Operators
SQL Operators are symbols or keywords used in SQL queries
to perform operations on data such as comparison, filtering,
and logical evaluation.
1. What are SQL Operators?
SQL operators are used with WHERE clause to specify conditions and filter records from tables.
- Used in SELECT, UPDATE, DELETE
- Help in decision making
- Improve query precision
2. Categories of SQL Operators
- Logical Operators
- Comparison Operators
- Special Operators
3. AND Operator
The AND operator returns TRUE if all conditions are TRUE.
SELECT * FROM student WHERE Marks > 70 AND CourseID = 101;
4. OR Operator
The OR operator returns TRUE if any one condition is TRUE.
SELECT * FROM student WHERE Marks > 85 OR CourseID = 102;
5. IN Operator
The IN operator allows multiple values in a WHERE clause.
SELECT * FROM student WHERE CourseID IN (101, 103, 105);
- Alternative to multiple OR conditions
6. BETWEEN Operator
The BETWEEN operator selects values within a given range.
SELECT * FROM student WHERE Marks BETWEEN 60 AND 80;
- Inclusive range
7. LIKE Operator
The LIKE operator is used to search for a pattern.
SELECT * FROM student WHERE Name LIKE 'A%';
- % → Any number of characters
- _ → Single character
8. LIMIT Operator
The LIMIT operator restricts the number of records returned.
SELECT * FROM student LIMIT 5;
- Used for pagination
9. IS NULL Operator
The IS NULL operator checks for NULL values.
SELECT * FROM student WHERE Email IS NULL;
10. Comparison of SQL Operators
Operator Purpose ----------- ---------------------------------- AND All conditions must be true OR Any one condition must be true IN Matches multiple values BETWEEN Matches range of values LIKE Pattern matching LIMIT Restricts result count IS NULL Checks NULL values
Practice Questions
- What are SQL operators?
- Explain AND and OR operators.
- Difference between IN and BETWEEN.
- What is LIKE operator?
- Write a query using LIMIT.
Practice Task
Write SQL queries to:
✔ Display students with marks between 60 and 90
✔ Display students whose name starts with 'S'
✔ Display top 3 students
✔ Display records where email is NULL