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.

2. Categories of SQL 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);

6. BETWEEN Operator

The BETWEEN operator selects values within a given range.

SELECT * FROM student
WHERE Marks BETWEEN 60 AND 80;

7. LIKE Operator

The LIKE operator is used to search for a pattern.

SELECT * FROM student
WHERE Name LIKE 'A%';

8. LIMIT Operator

The LIMIT operator restricts the number of records returned.

SELECT * FROM student
LIMIT 5;

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

  1. What are SQL operators?
  2. Explain AND and OR operators.
  3. Difference between IN and BETWEEN.
  4. What is LIKE operator?
  5. 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