CHP 3 Prac SQL
CHP 3 Prac SQL
-- 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
.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 "______________________________________________"
-- 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 "______________________________________________"
--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 "______________________________________________"
-- 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 "______________________________________________"