0% found this document useful (0 votes)
20 views10 pages

Dbms Slides

notes

Uploaded by

shwetha.csefac
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views10 pages

Dbms Slides

notes

Uploaded by

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

• If the names of the join attributes are not the same in the base relations, it is

possible to rename the attributes so that they match, and then to apply NATURAL
JOIN. In this case, the AS construct can be used to rename a relation and all its
attributes in the FROM clause.
• If the names of the join attributes are not the same in the base relations, it is
possible to rename the attributes so that they match, and then to apply NATURAL
JOIN using the AS construct.
• The implied join condition for this NATURAL JOIN is EMPLOYEE.Dno = DEPT.Dno,
because this is the only pair of attributes with the same name after renaming.
• The default type of join in a joined table is called an inner join, where a tuple is
included in the result only if a matching tuple exists in the other relation.
• For example, in query Q8A, only employees who have a supervisor are included
in the result. An EMPLOYEE tuple whose value for Super_ssn is NULL is excluded.

• If the user requires that all employees be included, a different type of join called
OUTER JOIN must be used explicitly.
• There are several variations of OUTER JOIN. We explicitly specify the keyword
OUTER JOIN in a joined table.
• ****************************
• It is also possible to nest join specifications; that is, one of the tables in a join may
itself be a joined table. This allows the specification of the join of three or more
tables as a single joined table, which is called a multiway join.
• A different syntax is used to specify outer joins by using the
comparison operators + =, = +, and + = + for left, right, and full outer
join, respectively, when specifying the join condition. For example,
this syntax is available in Oracle.
7.1.7 Aggregate Functions in SQL
• Aggregate functions are used to summarize information from multiple tuples
into a single-tuple summary.
• Grouping is used to create subgroups of tuples before summarization.
• A number of built-in aggregate functions exist: COUNT, SUM, MAX, MIN, and
AVG.
• COUNT returns the number of tuples or values as specified in a query.
• SUM, MAX, MIN, and AVG can be applied to a set or multiset of numeric
values and return, respectively, the sum, maximum value, minimum value, and
average (mean) of those values.
• These functions can be used in the SELECT clause or in a HAVING clause.
• MAX and MIN can also be used with attributes that have non-numeric
domains if the domain values have a total ordering among one another.
• Query 19. Find the sum of the salaries of all employees, the maximum
salary, the minimum salary, and the average salary.

• This query returns a single-row summary of all the rows in the


EMPLOYEE table.
• Using AS to rename the column names in the resulting single-row
table.
• Query 20. Find the sum of the salaries of all employees of the ‘Research’ department,
as well as the maximum salary, the minimum salary, and the average salary in this
department.

• Queries 21 and 22. Retrieve the total number of employees in the company (Q21) and
the number of employees in the ‘Research’ department (Q22).

• The asterisk (*) refers to the rows (tuples), so COUNT (*) returns the number of rows
in the result of the query
• We may also use the COUNT function to count values in a column rather
than tuple.
Query 23. Count the number of distinct salary values in the database.

• Using COUNT(SALARY) instead of COUNT(DISTINCT SALARY) will not


eliminate duplicate values.
• Any tuples with NULL for SALARY will not be counted.
• NULL values are discarded when aggregate functions are applied to a
particular column (attribute); the only exception is for COUNT(*)
because tuples instead of values are counted.

You might also like