OBJECTIVE:
The objective of this lab session is to learn Set operations Union, intersection, Except
and Aggregate Functions
Create this table Bikes and insert 5 Create this table Cars and insert 5
records records
create table bikes create table cars (
(bikes varchar (15), car varchar (15),
model varchar (15), model varchar (15),
Yearr varchar (15), Yearr varchar (15),
colour varchar (15), colour varchar (15),
owner_name varchar (15), owner_name varchar (15),
owner_id int ); owner_id int );
Task 1
1. Find union of car and owner_name
from both tables
2. Practice another union statement.
3. How to find distinct values using
union statement
4. Practice another union all statement
Task 2
1. Show only 1st row of table bikes
2. Show 1st three rows in table car
3. Practice except operator
4. Find intersection of car and bikes from
both tables
Task 3
1. Show the Count of total numbers of
records in table cars
2. Count total numbers of records in
table bikes
3. Retrieve the total Count number of
cars having colour grey
4. Show the total Count number of cars
having model 2011
5. Retrieve minimum year in cars
6. Display minimum model from the
table bikes
Task 4
1. Show maximum year in bikes
2. Display maximum model from the
table cars
3. Retrieve average owner_id in cars
4. Show average model from the table
bikes
5. Find sum of year in cars
create table cars (
car varchar (15),
model varchar (15),
Yearr varchar (15),
colour varchar (15),
owner_name varchar (15),
owner_id int );
insert into cars values ( 'car 1','2015','2011','red','saadia',1);
insert into cars values ( 'suzuki','2011','2008','black','saad',1);
insert into cars values ( 'mehran','2004','2017','white','Ali',1);
insert into cars values ( 'cultus','2000','2015','blue','umar',1);
insert into cars values ( 'audii','2011','2014','grey','sana ',1);
select * from cars
create table bikes
(bikes varchar (15),
model varchar (15),
Yearr varchar (15),
colour varchar (15),
owner_name varchar (15),
owner_id int );
insert into bikes values ( 'car 1','2015','2011','red','saadia',1);
insert into bikes values ( 'suzuki','2011','2008','black','saad',1);
insert into bikes values ( 'mehran','2004','2017','white','Ali',1);
insert into bikes values ( 'cultus','2000','2015','blue','umar',1);
insert into bikes values ( 'audii','2011','2014','grey','sana ',1);
select colour from bikes union all select colour from cars
select colour from bikes union select colour from cars
select colour from bikes select colour from cars
select COUNT(*) From cars
select COUNT(*) From cars where colour='grey'
select MIN(model) from cars
select MAX(model) from bikes
select AVG(owner_id) from bikes
Lab Grading Sheet :
Max Obtained
Task Comments(if any)
Marks Marks
1. 10
2. 10
3. 10
4. 10
Total 40 Signature
Note : Attempt all tasks and get them checked by your Lab. Instructor