Lab Manual No. 5
Lab Manual No. 5
CLO’s:
CLO-1
Semester:
Fall 2022
AIR UNIVERSITY ISLAMABAD
FACULTY OF ELECTRICAL AND COMPUTER ENGINEERING
Lab Objective:
To understand SQL wild cards and the operators used in SQL .
SQL Wildcards
SQL wildcards can be used when searching for data in a database.
SQL wildcards can substitute for one or more characters when searching for data in a database.
SQL wildcards must be used with the SQL LIKE operator.
With SQL, the following wildcards can be used:
Wildcard Description
or
[!charlist]
Next, we want to select the persons living in a city that contains the pattern "nes" from the
"Persons" table.
We use the following SELECT statement:
Next, we want to select the persons with a last name that do not start with "b" or "s" or "p" from
the "Persons" table.
SQL IN Operator
The IN operator allows you to specify multiple values in a WHERE clause.
SQL IN Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1,value2,...)
AIR UNIVERSITY ISLAMABAD
FACULTY OF ELECTRICAL AND COMPUTER ENGINEERING
IN Operator Example
The "Persons" table:
Now we want to select the persons with a last name equal to "Hansen" or "Pettersen" from the
table above.
We use the following SELECT statement:
The BETWEEN operator selects a range of data between two values. The values can be numbers,
text, or dates.
SELECT column_name(s)
FROM table_name
WHERE column_name
BETWEEN value1 AND value2
Example 2
To display the persons outside the range in the previous example, use NOT BETWEEN:
Lab Tasks:
• Write an SQL statement that selects all Customers with a Country starting with the letter “s”.
• Write an SQL statement that selects all Customers with a Contact Name ending with the letter
“s”.
• Write an SQL statement that selects all Customers with a City containing the pattern “ndo”.
• Write an SQL statement that selects all Customers with a City not containing the pattern
“ndo”.
• Write an SQL statement that selects the two first Customers from table who belong to
“Germany” or “Sweden”.
• Write an SQL statement that selects all Customers with a City of "Paris" or "London" without
using ‘OR’ operator.
AIR UNIVERSITY ISLAMABAD
FACULTY OF ELECTRICAL AND COMPUTER ENGINEERING