P. 1
From Clause & Tuples

From Clause & Tuples

|Views: 14|Likes:
Published by Ayisha

More info:

Published by: Ayisha on Jun 13, 2009
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PPTX, PDF, TXT or read online from Scribd
See more
See less





The from Clause

• The from clause lists the relations involved in the query
– corresponds to the Cartesian product operation of the relational algebra.

• Find the Cartesian product employee x department select  from employee, department s   Find the  employee name, deptno and deptname of all employees
select name, employee.eno, deptname  from employee, dept  where  employee. eno = dept.eno

Figure 3.3: Tuples inserted into

Figure 3.4:

select customer­name, T.loan­number, S.amount           from borrower as T, loan as S           where T.loan­number = S.loan­number s    Find the names of all branches that have greater assets than        some branch located in Brooklyn. select distinct T.branch­name     from branch as T, branch as S     where T.assets > S.assets and S.branch­city = ‘Brooklyn’

• Tuple variables are defined in the from clause via the use of the as clause. • Find the customer names and their loan numbers for all customers having a loan at some branch.

Tuple Variables

• Find all customers who have a loan, an account, or both:
(select customer­name from depositor) union (select customer­name from borrower) s    Find all customers who have both a loan and an  (select customer­name from depositor) intersect (select customer­name from borrower) s   Find all customers who have an account but no loan. (select customer­name from depositor) except (select customer­name from borrower)

Set Operations

Ordering the Display of List in alphabeticTuplesnames of all order the customers having a loan in Perryridge branch

select distinct customer-name from borrower, loan where borrower loan-number = loan.loan-number and branch-name = ‘Perryridge’ order by customer-name • We may specify desc for descending order or asc for ascending order, for each attribute; ascending order is the default.
– E.g. order by customer-name desc

Example 2
• Sailors (sid,sname, rating,age) • Boats(bid, bname,color) • Reserves(sid,bid ,date) • Refer to attached list for rows

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->