Professional Documents
Culture Documents
Grouping Records, Joins in SQL
Grouping Records, Joins in SQL
GROUP BY
• GROUP BY Clause combines all those records that have identical values in a particular field
or a group of fields.
• Grouping can done with aggregate functions
Syntax:
SELECT <column name>,aggregate_function
FROM <table name>
GROUP BY <column name>;
Student table
Emp table
Nested Groups -Grouping in multiple columns
To create a group within a group i.e. nested group we need to specify multiple fields in the
GROUP BY expression.
Eg: SELECT deptno,job,count(empno) FROM employee GROUP BY deptno ,job;
Having Clause
Cartesian Product
It is the all possible concatenations formed of all rows of both the tables that is,
when no particular rows and columns are selected. Such operation is also known as
Unrestricted join.It returns n1 x n2 rows.
SELECT * from employee,student123;
Table Aliases
JOIN
Equi-join and Natural join
SYNTAX
NATURAL JOIN