Lab 4
Lab 4
Instructor
Student Name
CMSID
Department
Semester
Lesson Set Introduction to Boolean logic and
Between operator syntax
4
Purpose 1. To get basic awareness of Boolean logics
2. To understand the SQL AND, OR, & NOT
3. How and where we can use these Booleans
4. Create new table and use the Boolean logic and between operator
Procedure 1. Students should read the Pre-lab Reading assignment before coming to lab.
2. Students should complete the Pre-lab Writing assignment before coming to
lab.
3. In the lab, students should complete Labs 4.1 through 4.4 in sequence.
Your instructor will give further instructions as to grading and completion of
the lab.
4. Students should complete the set of lab tasks before the next lab and get
them checked by their lab instructor.
Lab 4
26 | P a g e
PRE-LAB READING ASSIGNMENT
Boolean Logics
Boolean Logic refers to the words " AND, OR, NOT" and their intended usage
with manipulating databases to either add, include, or subtract populated
information from a data set. In other words, Boolean Logic refers to the logical
approach (AND) instead of the arithmetical approach (+) to retrieve
information from any database that contains data sets. The arithmetical
approach refers to using symbols to convey addition as opposed to the logical
sense which uses words.
The importance of using Boolean Logic when searching through databases is
that it allows you to have control over what information the database will
populate through your search in order to increase the efficiency and relevancy
of your results.
Below you will find examples of each of the instances when you
would use Boolean Logic and the results they would generate.
AND Syntax
OR Syntax
27 | P a g e
SELECT column1, column2, ...
FROM table_name
WHERE condition1 OR condition2 OR condition3 ...;
NOT Syntax
BETWEEN
Operator
The SQL BETWEEN condition allows you to easily test if an expression is
within a range of values (inclusive). The values can be text, date, or numbers.
It can be used in a SELECT, INSERT, UPDATE, or DELETE statement. The
SQL BETWEEN Condition will return the records where expression is within
the range of value1 and value2.
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
IN Operator
IN operator allows you to easily test if the expression matches any value in
the list of values. It is used to remove the need of multiple OR condition in
SELECT, INSERT, UPDATE or DELETE. You can also use NOT IN to
exclude the rows in your list. We should note that any kind of duplicate entry
will be retained.
SELECT column_name(s)
FROM table_name
WHERE column_name IN (list_of_values);
28 | P a g e
Pre lab writing assignment
Fill in the blanks 1. The __________ operator selects data if any one condition is true.
2. The SQL ___________ operator selects data if all conditions are true.
29 | P a g e
Lab 4.2 Lab Tasks
1. Use the 3.2.1 Database named by Courses and add new column by name fees using Alter
keyword syntax.
2. Write a query to Find all the students having first_name Between “A” and “K”. Using BETWEEN
with Date Values:
3. Write a query to Find the first_name, last_name of the students who have fees equal to 20000,
28000 or 25000.
4. Write a query to fetch all the records from the Student table where NAME is “yourChoice” OR
Age is greater then 17.
5. Write a query to fetch first_name, phone and email from the Student table where Age is 18 AND
first_name is “yourChoice” OR “yourChoice”.
6. Write a query to fetch all the records from the Student table where city is NOT equal to Quetta
30 | P a g e