Set Operators: 1. Union
Set Operators: 1. Union
Each operator requires that both tables have the same data types for the columns to which the operator is
applied.
JOINS
e. EXISTS
main query executes only if the sub query returns any few rows
<main query> EXISTS (<sub query>);
f. NOT EXISTS
main query executes only if the sub query does not return any rows
<main query> NOT EXISTS (<sub query>);
g. CONTAINS
A query selects what is selected by its correlated sub query
(<query>) CONTAINS (<query>);
h. EXCEPT
A query selects what is not selected by its correlated sub query
(<query>) EXCEPT (<query>);
i. GROUP BY CLAUSE
used to group same value in a column together and apply a group function to
it
Rule:
Select attributes and group by clause attributes should be same
Select <column1>, <column2> from <table name>
Where <conditions>
GROUP BY <column2>, <column1>;
j. HAVING CLAUSE
used to apply a condition to group by clause
Select <column1>, <column2> from <table name>
Where <conditions>
GROUP BY <column2>, <column1>
HAVING < conditions>;
k. ORDER BY CLAUSE
Used along with where clause to display the specified column in ascending
order or descending order .Default is ascending order
Select <column1>, <column2> from <table name>
Where <conditions>
ORDER BY <columns> DESC / ASC;
Example 1: List the name and salary of employees of the department 20 who
are leading a project that started before December 31, 1990:
Example 3: List all those employees who are working in the same department
as their manager
• For the clause any, the condition evaluates to true if there exists at least on row selected
by the subquery for which the comparison holds. If the subquery yields an empty result
set, the condition is not satisfied.
• For the clause all, in contrast, the condition evaluates to true if for all rows selected by
the subquery the comparison holds. In this case the condition evaluates to true if the
subquery does not yield any row or value.
Example 1: Retrieve all employees who are working in department 10 and who earn at
least as much as any (i.e., at least one) employee working in department 30:
Often a query result depends on whether certain rows do (not) exist in (other) tables. Such
type of queries is formulated using the exists operator.
Example 1: List all departments that have no employees: