Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Week 09 – Tutorial of Data

Query Language (DQL) Part 02


ITE 2422 - Database
Management Systems

Akila Warnapura
ITE 2422 - Database Management Systems Lecture Name:
Akila Warnapura Data Query Language (DQL)
Learning Outcomes
§ After completing this tutorial, you will learn about
Advanced data retrieval using Data Query Language (DQL)

ITE 2422 - Database


Management Systems

Akila Warnapura

Lecture Name:
Data Query Language (DQL)
Structured Query Language Commands

§ DDL - Data Definition Language


§ DCL - Data Control Language
§ DML - Data Manipulation Language
§ DQL - Data Query Language

ITE 2422 - Database


Management Systems

Akila Warnapura

Lecture Name:
Data Query Language (DQL)
Advanced Data Retrieval- SQL Joins

SQL Join Types


§ Inner Join
§ Outer Join
• Left Outer Join
• Right Outer Join
• Full Outer Join
§ Natural Join ITE 2422 - Database
§ Cross Join Management Systems

Akila Warnapura

Lecture Name:
Data Query Language (DQL)
Advanced Data Retrieval- SQL Joins

SQL Join Types


§ Inner Join
Join the tables by matching the given column or columns

ITE 2422 - Database


Management Systems

Akila Warnapura

Lecture Name:
Data Query Language (DQL)
Advanced Data Retrieval- SQL Joins

SQL Join Types


Outer Join
§ Left Outer Join
Join the tables by matching the given column or columns with all the tuples in left
hand side of the table.
§ Right Outer Join
Join the tables by matching the given column or columns with all the tuples in right
hand side of the table. ITE 2422 - Database
§ Full Outer Join Management Systems
Join the tables by matching the given column or columns with all the tuples in both left
and right hand sides of the table. Akila Warnapura

Lecture Name:
Data Query Language (DQL)
Advanced Data Retrieval- SQL Joins

SQL Join Types


§ Natural Join
Join the tables by automatically matching the similar names of the column or columns.

ITE 2422 - Database


Management Systems

Akila Warnapura

Lecture Name:
Data Query Language (DQL)
Advanced Data Retrieval- SQL Joins

SQL Join Types


§ Cross Join
Match each tuple in one table to all the tuples in the other table (without any
conditions) and form a new table.

ITE 2422 - Database


Management Systems

Akila Warnapura

Lecture Name:
Data Query Language (DQL)
Advanced Data Retrieval

Aggregate Functions in SQL

What is an aggregate function?


A single value is returned by an aggregate function after a calculation is performed on a
number of values.

There are several aggregate functions are available in SQL.

SUM() - Returns the total value of a column in a database table. ITE 2422 - Database
MIN() - Returns the minimum value of a column in a database table.
Management Systems
MAX() - Returns the maximum value of a column in a database table.
AVG() - Returns the average value of a column in a database table. Akila Warnapura
COUNT() - Returns the number of rows in a database table.
Lecture Name:
Data Query Language (DQL)
Advanced Data Retrieval

Nested Queries
A query that is contained within another SQL query and is incorporated into the WHERE
clause is referred to as a Subquery, Inner query, or Nested query.

The data that is returned from a subquery is then incorporated into the main query as a
condition to further restrict the amount of data that is retrieved from the database.

ITE 2422 - Database


Management Systems

Akila Warnapura

Lecture Name:
Data Query Language (DQL)
Advanced Data Retrieval

Correlated Nested Queries


A nested query which reading every row in a table and comparing the values in each row
against related data is called a correlated nested query or correlated subquery. It is utilized
in situations in which a subquery needs to return a different result or set of results for each
candidate row that the main query is looking at.

ITE 2422 - Database


Management Systems

Akila Warnapura

Lecture Name:
Data Query Language (DQL)

You might also like