0% found this document useful (0 votes)
18 views

CHP 3 Prac SQL

The document shows SQL commands used to demonstrate relational algebra operations like union, intersect, except, product and different types of joins like natural join, inner join, equijoin on tables like professor, student, booth and machine.

Uploaded by

Bree Elaine
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

CHP 3 Prac SQL

The document shows SQL commands used to demonstrate relational algebra operations like union, intersect, except, product and different types of joins like natural join, inner join, equijoin on tables like professor, student, booth and machine.

Uploaded by

Bree Elaine
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

-- P:\data\Yeslam\ITC114\Chp3>

-- sqlite3.exe chp3prac.db
-- https://mivuletech.wordpress.com/2011/03/22/an-overview-of-relational-algebra-
operators-and-their-sql-translations/
-- https://www.youtube.com/watch?v=tDaB9swAPtM
-- http://www.w3resource.com/sql/joins/perform-an-equi-join.php

.headers on
.mode column
.separator ,

.output chp3pracout.txt

select * from PROFESSOR;


select * from STUDENT;
select * from booth;
select * from machine;

.print "______________________________________________"

-- Union
.print "This is Union"
select * from booth union select * from machine;
.print "______________________________________________"

-- Intersect
.print "This is intersect"
select booth_price from booth intersect select machine_price from machine;
.print "______________________________________________"

select booth_price, booth_product from booth intersect select machine_price,


machine_product from machine;
.print "______________________________________________"

-- Except (Minus)
.print "This is Except (Minus)"
select * from booth except select * from machine;
.print "______________________________________________"

-- Product
.print "This is Product"
select * from booth, machine;
.print "______________________________________________"

-- ------------------------
-- a natural join
.print "This is natural join"
select * from professor natural join student;
.print "______________________________________________"

select stu_code, prof_code from professor natural join student;


.print "______________________________________________"

--inner join
.print "This is inner join"
select * from student inner join professor on
student.prof_code=professor.prof_code;
.print "______________________________________________"
select stu_code from student inner join professor on student.prof_code=
professor.prof_code;
.print "______________________________________________"

-- equijoin
.print "This is equijoin"
select * from student join professor on student.prof_code=professor.prof_code;
.print "______________________________________________"

select * from student, professor where student.prof_code=professor.prof_code;


.print "______________________________________________"

-- where condition
select * from student, professor where student.prof_code=professor.prof_code;
.print "______________________________________________"

-- outer join
.print "This is outer join"
select * from student left join professor on student.prof_code=professor.prof_code;
.print "______________________________________________"

-- Left Join
select * from student left join professor on student.prof_code=professor.prof_code;
.print "______________________________________________"

You might also like