SQL Operators

www.igif‮oc.aedit‬m

SQL operators are used to perform various operations on values in SQL queries. Some of the most commonly used SQL operators are:

  • =: checks for equality between two values.
  • <> or !=: checks for inequality between two values.
  • >: checks if one value is greater than another.
  • <: checks if one value is less than another.
  • >=: checks if one value is greater than or equal to another.
  • <=: checks if one value is less than or equal to another.
  • BETWEEN: checks if a value is between two other values.
  • LIKE: checks if a value matches a pattern.
  • IN: checks if a value is in a list of values.

For example, the following SQL statement selects all records from a table where the salary column is greater than or equal to 50000:

SELECT * FROM employees
WHERE salary >= 50000;

The following SQL statement selects all records from a table where the job_title column contains the word 'Manager':

SELECT * FROM employees
WHERE job_title LIKE '%Manager%';

In addition to these operators, SQL also provides logical operators such as AND, OR, and NOT, which can be used to combine multiple conditions in a single query. These operators are used to create complex conditions that can be used to filter records based on multiple criteria. For example, the following SQL statement selects all records from a table where the job_title column contains the word 'Manager' and the salary column is greater than or equal to 50000:

SELECT * FROM employees
WHERE job_title LIKE '%Manager%' AND salary >= 50000;