0% found this document useful (0 votes)
14 views15 pages

We Can Able To Display Group of Records, Summary of Group of Records and Display Selected Group of Records. in SQL There Are Two Types of Functions

Uploaded by

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

We Can Able To Display Group of Records, Summary of Group of Records and Display Selected Group of Records. in SQL There Are Two Types of Functions

Uploaded by

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

Ch – 13 Grouping and Join in SQL

We can able to display group of


records, Summary of group of records
and display selected group of records.
In SQL there are two types of
functions.
 1. Single Row Function.
 2. Multiple Row Function.
Single Row Function:
 It work with a single row at a time.
 It returns a result for every row of
queried table.
 Ex: substr ( ), round ( ), truncate ( )
Multiple Row Function:
 It work with data of multiple rows at a
time.
 It returns aggregated result.
 Ex: count ( ), max ( ), min ( )
Group by - Clause
It combine all those record that have
identical value in a particular field or a
group of fields.
It is used in select statement to divide
the table in groups.
Grouping can be done by a column
name or with aggregate function in
which case the aggregate produces a
value for each group.
Consider a Relation - Staff
Examples
1. Write a SQL query to display the No. of Employee
in each City wise.
2. Write a SQL query to display the No. of Employee
in each Department Wise.
3. Write a SQL query to display the Maximum and
Minimum salary in each Department wise.
4. Write a SQL query to display the Sum of the
Salary in each Department wise.
5. Write a SQL query to display the Maximum and
Minimum Salary based on particular department.
Nested Groups – Multiple Columns
With group by clause, we can create
groups within groups such type of
grouping is called nested grouping.
This can be done by specifying in
group by expression where the first
field determines the highest group
level, the second field determines the
second group level.
Consider a Relation - Member
Example – Nested Group
1. SELECT SCODE, DEPTNAME, COUNT(*) AS ‘TOTAL
NO. OF STAFF’ FROM SMEMBER GROUP BY
SCODE, DEPTNAME.
Having - Clause
The having clause places condition on
groups, in contrast to where clause
that places condition on individual
row. While where condition cannot
include aggregate functions having
condition can do so.
Basic Operations Based on Two Tables
in SQL
We can perform some basic operations
based on the two tables.
 Union – Using union keyword
 Cartesian Product – [cross product]
 Joins
 Natural Join [Using natural join keyword]
 Equi-Join [Using = operator]
Union
It is a process to combine the result set
of two select statements.
Using the keyword union we can
perform union operations between two
relation.
While performing union operation
based the two tables, those tables must
have a same number of columns and
same data type.
Cartesian Product
It is denoted by the symbol x.
It is a process of two tables, all possible
concatenation are formed of all rows of
both the tables.
Cartesian Product = Table 1 x Table 2
Consider the two relations:
 Members and Fruits.
Joins
A join is a query that combines rows
from two or more tables.
In a join-query , more than one tables
are listed in from clause.
The process of combining data from
multiple tables is called joining.
Different types of joins are:
 1. Equi-Join
 2. Natural Join
Equi – Join
The join, in which columns are
compared for equality, is called
‘Equi-Join’.
Using (= )operator create a Equi-join.
Identical column must be matched
with = operator.
Using Table alias we can check the
equality between the two tables.
Consider a Relation: Student and
Result.
Natural Join
The join, in which only one of the
identical columns exist is called
‘Natural Join’.
 Consider a Relation: [ Natural Join] – Ex.
 Customer and Bank
 Consider a Relation: [Equi Join] – Ex.
 [Personal, Student]

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy