You are on page 1of 7

8 Mark

1. Nested Subqueries
Ans:
SQL provides a mechanism for subqueries. Earth subquery is a
select-from-where expression that is nested within another
query.
Lets See About
 SET MEMBERSHIP
 SET COMPARISON
 SET CO-ORDINALITY

 SET MEMBERSHIP:
It allows testing tuples for membership in a relation.
The in-connectives tests for set membership where these set is a
collection of values produced by a select clause.
The not in connective tests for the absence of set membership.
Query for all account holders at the bank who are the members
of the set of borrowers from the bank.
Select distinct customer_name
From borrower
Where customer_name in [ Select customer name from
depositor]

 SET COMPARISON:
The phrase “Greater than at least one” is represented in SQL
by > some
Select branch name
From branch
Where asserts some [ Select assets from branch where
branch.city=’Chennai’]
The Subquery [ Select assets from branch where
branch.city=’Chennai’] Generates the set of all assert values
branches in Chennai . The > some comparison in the where
clause of the outer select is true is the assets value of the tuple is
greater than at least one member of the set of all asset values for
branches in Chennai.

Find the branch that has the highest average balance:


Select branch name
From branch
Group by branch name having avg(balance)>= all (Select
avg balance from account group by branch_name)
 SET CO-ORDINALITY:
 Tesr for Empty

Exits
Non-Exits
Except

 Test for absence of duplicate tuple

Unique

Non-Unique

SQL joins
Types of joints
 INNER JOIN
 LEFT OUTER JOIN
 RIGHT OUTER JOIN
 FULL OUTER JOIN
 INNER JOIN:

Select Column from table 1


INNER JOIN table2 ON
Table1.column=table2.column
Definition:
it returns all rows from multiple table where the joint condition
is met.

 LEFT OUTER JOIN:


Select Column from table 1
LEFT OUTER JOIN table2 ON
Table1.column=table2.column
Definition:
It returns all rows from the left hand table specified in the on
condition and only those rows from the other table where the
joined fields are equal.

 RIGHT OUTER JOIN:


Select Column from table 1
RIGHT OUTER JOIN table2 ON
Table1.column=table2.column

Definition:
It returns all rows from the right hand table specified in the on
condition and only those rows from the other table where the
joined fields are equal.

 FULL OUTER JOIN:


Select Column from table 1
FULL OUTER JOIN table2 ON
Table1.column=table2.column

Definition:
It returns all rows from the left hand table and right hand table
with the null values in place where the joied condition is not
met.

You might also like