Professional Documents
Culture Documents
Labsheet 8
Labsheet 8
IS222 – DATABASE
CONCEPTS AND DESIGN
Lab sheet
Lab 8: SELECT statement with WHERE
IS222
Table of Contents
LAB 8: SELECT Statement with WHERE..............................................................................2
Objectives:..........................................................................................................................................2
Tools/Software:..................................................................................................................................2
Concepts & Descriptions:.................................................................................................................2
SELCET Statement with WHERE..................................................................................................2
Examples and explanations of SELECT statement with WHERE...............................................3
Examples and explanations of SELECT statement with DISTINCT...........................................4
LIKE Operator..................................................................................................................................5
Examples and explanations of SELECT with LIKE operator......................................................5
Lab Activities:....................................................................................................................................6
Deliverables:.......................................................................................................................................7
LAB 8: SELECT Statement with WHERE
Objectives:
This lesson covers the following objectives:
Tools/Software:
To accomplish this session, students should have access to APEX.
Using where with BETWEEN SELECT stud_name FROM students This command retrieves student name
WHERE stud_GPA BETWEEN 3.5 AND column from students table that their GP
4.5 are not less than 3.5 and not more than
Using where with IN SELECT stud_name FROM students This command retrieves student name
WHERE stud_dept IN ('IS','CS') column from students table that their
departments are either IS or CS.
Using where with AND Select * This command retrieves all columns from
FROM students students table that named Ahmed and th
WHERE stud_name='Ahmed' AND ages are greater than 19.
stud_age >19
Using where with OR SELECT stud_name,stud_id FROM This command retrieves student name a
students WHERE Stud_name = student_id columns from student table t
'Ahmed' OR stud_age =20 named Ahmed, or their ages is 20.
using where with NOT SELECT * FROM students WHERE NOT This command retrieves all columns from
Stud_name ='Ahmed' students table that named not Ahmed.
Using where with IS NULL SELECT * FROM students WHERE This command retrieves all columns from
stud_dept IS NULL students table whose stud_dept is null
(empty).
Examples and explanations of SELECT statement with DISTINCT
Search based on last SELECT * FROM student WHERE This command retrieves all column from
character stud_name LIKE '%a' students table that their students name end
‘a’ letter.
Search based on first and SELECT * FROM student WHERE This command retrieves all column from
last character stud_name LIKE 'a%d' students table that their students name star
with ‘a’ letter and end with ‘d’ letter.
Search based on character in SELECT * FROM student WHERE This command retrieves all column from
any position stud_name LIKE '%a%' students table that their students name
contained of ‘a’ letter.
SELECT * FROM students WHERE This command retrieves all column from
Stud_name LIKE '_n%' students table that their second letter of
students’ name are’ n’.
Search based on second The 1st character can be anything, the 2
character must be ‘n’ and the next characters can
none, one or more.
SELECT * FROM students WHERE This command retrieves all column from
Stud_name LIKE '_n_' students table that their second letter of
students’ name are’ n’.
The 1st character can be anything ,2nd
character 'n' and any 3rd character. The
name should consist of only 3 letters.
Lab Activities:
1. Write the SQL command to retrieve all columns from MOVIES table that have R
rating and their categories are DRAMA.
2. Write the SQL command to retrieve Title of movies from MOVIES table that their
categories are FANTASY or DRAMA.
3. Write the SQL command to retrieve all records from MOVIES table excepted
records that their categories are ANIMATION.
SELECT * FROM MOVIES WHERE CATEGORY <> 'ANIMATION';
4. Write the SQL command to retrieve all columns from MOVIES table that have PG
Rating and their categories are DRAMA OR FANTASY.
5. Write the SQL command to retrieve all columns from MOVIES table that their
titles start with ‘a’ letter.
6. Write the SQL command to retrieve all movies from MOVIES table that their
titles end with ‘s’ letter.
7. Write the SQL command to retrieve title of movies from MOVIES table that their
titles end with ‘s’ letter and start with ’R’ letter.
8. Write the SQL command to retrieve title of movies from MOVIES table that third
letter of their titles is ’e’.
SELECT TITLE FROM MOVIES WHERE TITLE LIKE '__e%';
Deliverables:
At the end of this session, students are expected to:
Solve the lab activities and submit their work.