Professional Documents
Culture Documents
Structured Query
Language
(SQL)
Assistant Lecturer Huda A.
Alameen
hudaa.alameen@uokufa.edu.iq
SQL
▶ retrieving data from the database by specifying which columns and rows to be
retrieved
▶ The basics syntax for select statement is :
Country
Germany
UK
Sweden
WHERE
▶ Commonly 3 clauses (SELECT, FROM, WHERE) are used
▶ Query: List the names of the capital cities in the CITY
table.
SQL and, or Syntax
▶ The syntax for and condition is:
▶ The LIKE operator is used in a WHERE clause to search for a specified pattern
in a column.
▶ There are two wildcards often used in conjunction with the LIKE operator:
▶ % - The percent sign represents zero, one, or multiple characters
▶ _ - The underscore represents a single character
▶ LIKE Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1, value2, ...);
▶ or:
SELECT column_name(s)
FROM table_name
WHERE column_name IN
(SELECT STATEMENT);
SELECT * FROM Customers
WHERE Country IN ('Germany', 'France', 'UK');
SELECT * FROM Customers
WHERE Country NOT IN ('Germany', 'France', 'UK');
BETWEEN Operator
▶ The BETWEEN operator selects values within a given range. The values can be
numbers, text, or dates.
▶ The BETWEEN operator is inclusive: begin and end values are included.
▶ BETWEEN Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
Example
6 Select employees that earn salaries between 1000 and 2000 dollar
Ans:
Select * from Employees WHERE Salary BETWEEN 1000 AND 2000