Professional Documents
Culture Documents
3.chapter 3
3.chapter 3
3.chapter 3
P.Uruthiran
puruthiran@gmail.com
ICT-UNIVOTEC
Note: If the WHERE clause is omitted all rows of data are deleted from the table.
Database Analysis and
ICT-UNIVOTEC 17 Design - B.Tech
SQL Statements, Operations, Clauses
SQL Statements:
Select
SQL Operations:
Join
Left Join
Right Join
Like
SQL Clauses:
Order By
Group By
Having
Database Analysis and Design -
ICT-UNIVOTEC 18 B.Tech
SQL: SELECT Statement
A basic SELECT statement includes 3 clauses
Emp Dept
ID State ID Division
1000 CA 1001 IT
1001 MA 1002 Sales
1002 TN 1003 Biotech
ICT-UNIVOTEC Database Analysis and Design - B.Tech 22
inner join = join
SELECT *
FROM emp join dept (or FROM emp, dept)
on emp.id = dept.id;
Database
Analysis and
ICT-UNIVOTEC 23 Design - B.Tech
left outer join = left join
SELECT *
FROM emp left join dept
on emp.id = dept.id;
Database
Analysis and
ICT-UNIVOTEC 24 Design - B.Tech
right outer join = right join
SELECT *
FROM emp right join dept
on emp.id = dept.id;
Database
Analysis and
ICT-UNIVOTEC 25 Design - B.Tech
Join operations take two relations and
return as a result another relation.
A join operation is a Cartesian product
which requires that tuples in the two
relations match (under some condition). It
also specifies the attributes that are
present in the result of the join
The join operations are typically used as
subquery expressions in the from clause
Relation prereq
Observe that
prereq information is missing for CS-315 and
course information is missing for CS-437
ICT-UNIVOTEC Database Analysis and Design - B.Tech 27
An extension of the join operation that
avoids loss of information.
Computes the join and then adds tuples form
one relation that does not match tuples in
the other relation to the result of the join.
Uses null values.
COUNT(attr)
SUM(attr)
MAX(attr)
MIN(attr)
AVG(attr)
02/26/08 pizza 70
02/26/08 pizza 70
select name
from instructor
where salary > some (select salary
from instructor
where dept_name = ’Biology’);
or equivalently
insert into course (course_id, title, dept_name, credits)
values (’CS-437’, ’Database Systems’, ’Comp. Sci.’, 4);