0% found this document useful (0 votes)
10 views61 pages

2.2-DQL Adc

This document provides an outline and overview of the SQL and database concepts that will be covered in the CS820 Advanced Database Concepts course. It discusses topics like SQL introduction, Data Query Language, SELECT, WHERE, FROM, GROUP BY, HAVING clauses and provides examples of how to use each. It also covers concepts like pattern matching, escape characters, and the relationship between COUNT, NULL, DISTINCT and ALL.

Uploaded by

Red Ghost
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)
10 views61 pages

2.2-DQL Adc

This document provides an outline and overview of the SQL and database concepts that will be covered in the CS820 Advanced Database Concepts course. It discusses topics like SQL introduction, Data Query Language, SELECT, WHERE, FROM, GROUP BY, HAVING clauses and provides examples of how to use each. It also covers concepts like pattern matching, escape characters, and the relationship between COUNT, NULL, DISTINCT and ALL.

Uploaded by

Red Ghost
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/ 61

CS820: ADVANCED DATABASE CONCEPTS

MSIT 2k23
LECTURE OUTLINE
 SQL-Introduction
 Data Query Language (DQL)
 SELECT
 WHERE
 FROM
 GROUP BY
 HAVING

2
SQL INTRODUCTION
MYSQL & SQL

4
5
DQL || DRL

6
DATA QUERY LANGUAGE

SELECT column, group_function(column)


FROM table
[WHERE condition]
[GROUP BY group_by_expression] 7
[HAVING group_condition]
[ORDER BY column];
WHAT IS SQL

8
SQL SYNTAX

9
EXAMPLE

10
SQL WORK FLOW

11
OTHER ASPECT OF SQL

12
SQL –DML / DQL

13
SELECT CLAUSE

14
SELECT CLAUSE EXAMPLE

15
SELECT CLAUSE EXAMPLE

16
FROM CLAUSE

17
FROM CLAUSE EXAMPLE

18
FROM CLAUSE EXAMPLE

19
WHERE CLAUSE

20
SCALAR EXPRESSION IN SQL

21
WHERE CLAUSE EXAMPLE

22
PATTERN MATCHING

23
PATTERN MATCHING

24
PATTERN MATCHING -EXAMPLE

25
ESCAPE CHARACTER
ESCAPE CHARACTER
GROUP BY AND HAVING
GROUP BY CLAUSE
SPLIT APPLY COMBINE
POINT TO REMEMBER
GROUP BY CLAUSE- EXAMPLE
HAVING CLAUSE
HAVING CLAUSE- EXAMPLE
GROUP BY AND ORDER BY
GROUP BY AND HAVING
Relation b/w COUNT, NULL, DISTINCT, ALL
Test Case#1: Count(*); NULL in Salary

Conclusion: All the tuples have been counted.


Relation b/w COUNT, NULL, DISTINCT, ALL
Test Case#2: Count(Salary); NULL in Salary

Conclusion: Count ignores “NULL” and don’t put it into consideration while counting.
Relation b/w COUNT, NULL, DISTINCT, ALL
Test Case#3: Count(DISTINCT Salary); NULL in Salary

Conclusion: Count ignores “NULL” and don’t put it into consideration while counting whether
DISTINCT is being used or not.
Relation b/w COUNT, NULL, DISTINCT, ALL
Test Case#4: Count(ALL Salary); NULL in Salary

Conclusion: Count ignores “NULL” even if ALL is used. In fact, use of ALL is not making any sense
in here and the query behaves same without ALL.
Revisit!

Not need of ALL; count at


any case ignores NULL and
count the non-null values
only.
Relation b/w GROUP BY, HAVING &
Aggregated Attribute
Test Case#1: GROUP BY without Aggregated Attribute

Conclusion: GRIOUP BY can work without aggregated attribute and vice versa
Relation b/w GROUP BY, HAVING &
Aggregated Attribute
Test Case#2: GROUP BY with Aggregated Attribute

Conclusion: GRIOUP BY doesn’t


allow aggregated attribute to
appear within its clause but in the
SELECT clause if HAVING is not
there
Relation b/w GROUP BY, HAVING &
Aggregated Attribute
Test Case#3: GROUP BY + HAVING with Aggregated Attribute and SELECT without Aggregated attribute

Conclusion: The aggregated


attribute need not to be the part of
SELECT if GROUP BY and
HAVING is used.
Relation b/w GROUP BY, HAVING &
Aggregated Attribute
Test Case#4: GROUP BY + HAVING with Aggregated Attribute and SELECT with Aggregated attribute

Conclusion: The aggregated


attribute can be a part of SELECT
if it needs to be displayed in the
result
THANK YOU

You might also like