0% found this document useful (0 votes)
3 views1 page

Lab Manual Portion

The document outlines various SQL commands and operators, including renaming tables, selecting employee names based on join dates, and set-manipulation constructs like UNION, INTERSECT, and EXCEPT (MINUS). It also explains the use of IN, NOT IN, EXISTS, and NOT EXISTS operators, as well as aggregate functions such as COUNT, SUM, AVG, and MIN. Additionally, it describes the ORDER BY clause for sorting query results in ascending or descending order.

Uploaded by

Pradipta Pal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Lab Manual Portion

The document outlines various SQL commands and operators, including renaming tables, selecting employee names based on join dates, and set-manipulation constructs like UNION, INTERSECT, and EXCEPT (MINUS). It also explains the use of IN, NOT IN, EXISTS, and NOT EXISTS operators, as well as aggregate functions such as COUNT, SUM, AVG, and MIN. Additionally, it describes the ORDER BY clause for sorting query results in ascending or descending order.

Uploaded by

Pradipta Pal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Renaming the tables

Syntax:
Rename oldtable to new table; Ex: rename emp to emp1;
List all the employee names who joined after particular date
SQL select e,empname from employee e,paydet p where e.empid=p.empid and p.doj=’05-mar-06’;

UNION, INTERSECT, EXCEPT (MINUS) :- SQL provides three set-manipulation constructs that extend the basic query form.
Since the answer to a query is a multiset of rows, it is natural to consider the use of operations such as union, intersection, and
difference.
SQL supports these operations under the names UNION, INTERSECT and MINUS.

Note that UNION, INTERSECT, and MINUS can be used on any two tables that are union compatible, that is, have the same
number of columns and the columns, taken in order, have the same types.

UNION :- It is a set operator used as alternative to OR query.


Here is an example of Query using OR.

INTERSECT :- It is a set operator used as alternative to AND query. Here is an example of


Query using AND.

EXCEPT (MINUS) :- It is a set operator used as set-difference. Our next query illustrates
the set-difference operation.

IN Operator :- The IN operator allows us to test whether a value is in a given set of elements; an SQL query is used to generate the
set to be tested.

NOT IN Operator :- The NOT IN is used in a opposite manner to IN.

EXISTS Operator :- This is a Correlated Nested Queries operator. The EXISTS operator is another set comparison operator, such
as IN. It allows us to test whether a set is nonempty, an implicit comparison with the empty set.

NOT EXISTS Operator :- The NOT EXISTS is used in a opposite manner to EXISTS.
Set-Comparison Operators:- We have already seen the set-comparison operators EXISTS, IN along with their negated versions.
SQL also supports op ANY and op ALL, where op is one of the arithmetic comparison operators {<, <=, =, <>, >=, >}. Following are
the example which illustrates the use of these Set-Comparison Operators.
op ANY Operator :- It is a comparison operator. It is used to compare a value with any of element in a given set.
op ALL Operator :- It is a comparison operator. It is used to compare a value with all the elements in a given set.
AGGREGATE Functions :- In addition to simply retrieving data, we often want to perform some computation or summarization. We
now consider a powerful class of constructs for computing aggregate values such as MIN and SUM. These features represent a
significant extension of relational algebra. SQL supports five aggregate operations, which can be applied on any column, say A, of
a relation:
1. COUNT (A) :- The number of values in the A column.
Or COUNT (DISTINCT A): The number of unique values in the A column.
2. SUM (A) :- The sum of all values in the A column.
Or SUM (DISTINCT A): The sum of all unique values in the A column.
AVG (A) :- The average of all values in the A column.
Or AVG (DISTINCT A): The average of all unique values in the A column.
5. MIN (A) :- The minimum value in the A column.
ORDER BY Clause :- The ORDER BY keyword is used to sort the result-set by a specified
column. The ORDER BY keyword sorts the records in ascending order by default (we can even
use ASC keyword). If we want to sort the records in a descending order, we can use the DESC
keyword. The general syntax is
SELECT ATT_LIST FROM TABLE_LIST ORDER BY ATT_NAMES [ASC | DESC];

You might also like