You are on page 1of 2

The SQL AND, OR and NOT Operators

AND, OR, and NOT operators are combined with the WHERE clause. In order to filter records based o
on more than one condition, the AND, OR operators are used. However AND, OR, NOT operators can be
applied through combining.

 AND operator shows record s if all the conditions are separated by AND or TRUE.

AND Syntax:

SELECT column1,  column2,...
FROM table_name
WHERE condition1 AND condition2 AND condition3 ...;
 The OR operator displays a record if a condition is separated by OR is TRUE.
OR Syntax:

SELECT column1,  column2,...
FROM table_name
WHERE condition1 OR condition2 OR condition3 ...;
 NOT Syntax:
SELECT column1,  column2,...
FROM table_name
WHERE NOT condition;

The SQL ORDER BY Keyword


In order to sort the result set in ascending to descending order the ORDER BY keyword is used. By
default, the record is sorted in ascending order. In order to sort it in descending order, DESC keyword is
used. This keyword can be used to sort by several columns too.
OEDER BY syntax:

SELECT column1,  column2,...
FROM table_name
ORDER BY column1, column2,...  ASC|DESC;

SQL INSERT INTO Statement
To insert a new record in a table the INSERT INTO statement is used.
INSERT INTO Syntax:
There are two ways to write insert into statement.
The first way:

INSERT INTO table_name (column1,  column2,  column3,...)


VALUES (value1,  value2,  value3, ...);
To add values of all the columns of the table, it is not necessary to specify the column names in the SQL
query. However, the order of the values should be in the same order as the columns in the table.

You might also like