AND operator displays a record if ALL the conditions are TRUE. ORoperator displays a record if ANY of the conditions are TRUE.
Example AND in WHERE: the following SQL selects all fields from Customers where country is "Germany" AND City is "Berlin" AND PostalCode is higher than 1200
SELECT * FROM customers WHERE Country = 'Germany' AND City = 'Berlin', AND PostalCode > 1200
Example AND + Nested OR: select all Spanish customers that start with either "G" or "R"
SELECT * FROM Customers WHERE Country = 'Spain' AND (CustomerName LIKE 'G%' OR CustomerName LIKE 'R%')
SQL OR
OR operator is used to filter records based on more than onecondition
OR in WHERE Syntax: SELECT columnName, columnName, ... FROM tableName, tableName, ... WHERE condition1 OR condition2 OR condition3 ...
Example OR in WHERE: select all customers from Germany or Spain
SELECT * FROM Customers WHERE Country = 'Germany' OR Country = 'Spain'
SQL NOT
NOT operator is used in combination with other operators to give the opposite result, also called the negative result.
NOT Syntax: SELECT columnName, columnName, ... FROM tableName, tableName WHERE NOT condition;
Example NOT: select only the customers that are NOTfrom Spain
SELECT * FROM Customers WHERE NOT Country = 'Spain'
Example NOT: select customers that does not start with the letter 'A'
SELECT * FROMCustomersWHERE CustomerName NOT LIKE 'A%'
Example NOT, AND & BETWEEN: select customers with a CustomerID notbetween10 and 60
SELECT * FROM Customers WHERE CustomerID NOT BETWEEN 10 AND 60
Example NOT IN: select customers that are not from Paris or London
SELECT * FROM Customers WHERE City NOT IN ('Paris', 'London')
Example NOT: select customers with a CustomerID not greater than 50
SELECT * FROM Customers WHERE NOTCustomerID > 50
SQL INSERT INTO
Used to insert new records into a table
Syntax: INSERT INTO tableName(columnName, columnName, ...)VALUES(value1, value2, ...); INSERT INTO tableName VALUES(value1, value2, value3, ...);
Example: insert a new record in the customers table
INSERT INTO Customers (CustomerName, City, Country) VALUES('Cardinal', 'Stavenger', 'Norway')