Logo

K-Learn

SQL AND, OR, NOT Operator

< Previous Next >

The AND operator is used to combine two or more conditions in a WHERE clause, and only rows that meet all of the conditions will be included in the result set. 

AND Syntax

SELECT column1, column2, …
FROM table_name
WHERE condition1 AND condition2 AND condition3 ...;

For example,

The following SQL statement retrieves all the records from the "student" table where the student's name is 'John Doe' and their email is 'john.doe@example.com':

We can use the following SQL statement:

SELECT * FROM student WHERE name = 'John Doe' AND email = 'john.doe@example.com';

OUTPUT

OR Operator

The OR operator is used to combine two or more conditions in a WHERE clause, and rows that meet at least one of the conditions will be included in the result set.

OR Syntax

SELECT column1, column2, …
FROM table_name
WHERE condition1 OR condition2 OR condition3 ...;

For example,

The following SQL statement retrieves all the records from the "student" table where the student's name is 'Angel' or their email is 'john.doe@example.com':

We can use the following SQL statement:

SELECT * FROM student WHERE name = 'Angel' OR email = 'john.doe@example.com';

OUTPUT

NOT Syntax

SELECT column1, column2, …
FROM table_name
WHERE NOT condition;

NOT Operator

The NOT operator is used to negate a condition in a WHERE clause.

For example,

The following SQL statement retrieves all the records from the "student" table where the student's name is not 'John':

We can use the following SQL statement:

SELECT * FROM student WHERE NOT name = 'John';

OUTPUT


< Previous Next >