Which operator is used for all types of queries?

These SQL operators are considered as a set of reserved words used in SQL Where clause. They specify the condition and also serve as a conjunction for multiple conditions in a statement. In this tutorial, we will discuss on:

  • How to Impose Conditions using SQL Operators?
  • AND Operator in SQL and its syntax
  • SQL OR Operator and its syntax
  • NOT Operator in SQL and its syntax

Watch this Operators in SQL video

How to Impose Conditions using SQL Operators?

As in the earlier Where clause section, we saw how one condition is passed. But when there are multiple conditions applied to a table to filter the data, the operators are used. There are two conditions: first, the age should be greater than 60 and, second, the occupation must be doctor. Only when these conditions are met, the AND operator displays values.
There are three types of operators:

  • AND Operator in SQL
  • OR Operator in SQL
  • NOT Operator in SQL

lets look each of them in detail

AND operator in SQL and its syntax:

The AND operator displays only those records where all conditions are evaluated to true. For example, if you want to find out all the doctors aged greater than 60, the syntax would be as follows.

Syntax

SELECT column1, column2, …, columnN
FROM tablename
WHERE [condition1], … AND [conditionN];

where SELECT, FROM, WHERE, and AND are the keywords; column1 to columnN are a set of columns; tablename is the name of the table, and condition1 to conditionN are a set of conditions followed by a semicolon.

  • Let’s display all employees whose age is below 30 and who belong to the operations department from the employee table
Select e_name, e_age, e_salary From employee where e_age

Chủ Đề