Page 2 - Grouping Records and Join in SQL
P. 2
HAVING clause
Having clause is used to filter the groups created by group by clause.
Places condition only on the field on which group is made or on statistical function.
select job, count(*), avg(sal)
from employee
group by job
having job = 'CLERK';
select job, count(*), avg(sal)
from employee
group by job
having count(*)<3;
Order of combining clauses
SELECT column list
FROM <table name>
WHERE <predicate>
GROUP BY <column name(s)>
HAVING <search condition>
ORDER BY column_name;
Extracting data from two tables
Cartesian Product
Required for a SQL query when data needs to be extracted from two tables.
Cartesian product forms a new table of degree (c1+c2) and of cardinality (r1 x r2), where c1 and r1
are the degree and cardinality (respectively) of student and c2 and r2 is that of stream.
e.g. To display names of students along with the names of their stream from the following tables.