Presentation is loading. Please wait.

Presentation is loading. Please wait.

Set Operations Union Intersect Minus.

Similar presentations


Presentation on theme: "Set Operations Union Intersect Minus."— Presentation transcript:

1 Set Operations Union Intersect Minus

2 Union Returns all distinct rows from both queries. Example
SQL> Select * from emp1 union select * from emp2; A={ 1,5,6,3} b= {6,8,4,3,2} AUB = { 1,5, 6,3,8,4,2} SQL> select city from salesman union select city from customer;

3 UNION ALL Display including duplicates record Example
SQL> Select * from emp1 union all select * from emp2; A={ 1,5,6,3} b= {6,8,4,3,2} AUB = { 1,5, 6,3,6,8,4,3,2} SQL> select city from salesman union all select city from customer;

4 Intersect Returns common rows selected by both queries Example
SQL> Select * from emp1 intersect select * from emp2; A={ 1,5,6,3} b= {6,8,4,3,2} A∩B = { 6,3 } SQL> select city from salesman intersect select city from customer;

5 Minus Returns all distinct rows that are in the first query, but not in second one. Example SQL> Select * from emp1 minus select * from emp2; A={ 1,2,3,4,5,6} b= {5,6} A-B = { 1,2,3,4} SQL> select city from salesman minus select city from customer;

6 Aggregate Functions

7 Aggregate Functions Aggregate function are functions that take a collection of values as input and return a single value as output. AVG – average value MIN – minimum value MAX – Maximum value SUM – Sum of values COUNT – number of record

8 Std Sno Name Create table Mark1 Mark2 Mark3 SQL> select avg(mark1) from std; SQL> select avg(mark1), avg(mark2), avg(mark3) from std where mark1>=60;

9 SQL> select min(mark1) from std;
SQL> select max(mark1) from std; SQL> select sum(mark1) from std; SQL> select count(*) from std where mark>=60 and mark2>=60 and mark3>=60;

10 Embedded SQL The SQL standard defines embeddings of SQL in a variety of programming languages such as Pascal, PL/1, FORTRAN, C and COBAL. A language to which SQL queries are embedded is referred to as a host language, and the SQL structures permitted in the host language comprise embedded SQL. The basic of these languages follows that of the system R embedding of SQL into PL/1’s

11 Dynamic SQL The dynamic SQL component of SQL allows programs to construct and submit SQL queries at run time. In contrast, embedded SQL statements must be completely present at compile time, they are compiled by the embedded SQL preprocessor. Using dynamic SQL programs can create SQL queries as strings at runtime and can either have them executed immediately or have them prepared for sub sequent use.


Download ppt "Set Operations Union Intersect Minus."

Similar presentations


Ads by Google