Professional Documents
Culture Documents
Learning objectives:
Use arithmetic operators in SQL statements
Select rows from a table with conditional restrictions
Apply logical operators to have multiple conditions
Syntax
SELECT column1, column2, ...
FROM table_name;
Syntax
SELECT DISTINCT column1, column2, ...
FROM table_name;
Select ALL (including the duplicates) values from the "Country" column in the "Customers" table.
SELECT Country FROM Customers;
Select only the DISTINCT values from the "Country" column in the "Customers" table:
SELECT DISTINCT Country FROM Customers;
Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition;
Select all the customers from the country "Mexico", in the "Customers" table:
SELECT * FROM Customers
WHERE Country='Mexico';
Select the customer with a specific customer ID from the "Customers" table:
SELECT * FROM Customers
WHERE CustomerID=1;
Select all fields from "Customers" where country is "Germany" AND city is "Berlin":
SELECT * FROM Customers
WHERE Country='Germany' AND City='Berlin';
3.3.2 OR operator
Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition1 OR condition2 OR condition3 ...;
Select all fields from "Customers" where country is "Germany" AND city must be "Berlin" OR
"London" (use parenthesis to form complex expressions):
SELECT * FROM Customers
WHERE Country='Germany' AND (City='Berlin' OR City='London');
Select all fields from "Customers" where country is NOT "Germany" and NOT "USA":
SELECT * FROM Customers
WHERE NOT Country='Germany' AND NOT Country='USA';