0% found this document useful (0 votes)
4 views9 pages

Advanced SQL Query Techniques Explained

The document provides an overview of advanced SQL queries, including examples of GROUP BY, WHERE, HAVING, nested SELECT statements, and various types of JOINs. It features a sample employee table with 20 rows detailing employee information such as ID, name, department, salary, and joining date. The document illustrates how to use SQL commands to manipulate and retrieve data effectively from the employee dataset.

Uploaded by

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

Advanced SQL Query Techniques Explained

The document provides an overview of advanced SQL queries, including examples of GROUP BY, WHERE, HAVING, nested SELECT statements, and various types of JOINs. It features a sample employee table with 20 rows detailing employee information such as ID, name, department, salary, and joining date. The document illustrates how to use SQL commands to manipulate and retrieve data effectively from the employee dataset.

Uploaded by

DipankarDutta
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Advanced SQL Queries with

Examples
Group By | Where | Having | Nested
Select | Joins | Union
Sample Employee Table (20 Rows)
• EmpID Name Department Salary JoiningDate
1 Alice HR 50000 2022-01-15
2 Bob IT 60000 2021-03-22
3 Charlie Finance 55000 2020-06-10
4 David IT 65000 2021-07-19
5 Eva Finance 70000 2019-08-25
6 Frank HR 48000 2023-02-05
7 Grace IT 72000 2022-11-30
8 Hannah Finance 67000 2021-12-17
9 Ian IT 58000 2020-09-08
10 Jack HR 52000 2022-05-14
11 Karen Finance 75000 2018-11-21
12 Leo IT 80000 2019-01-19
13 Mona Finance 71000 2020-03-10
14 Nina IT 64000 2023-04-15
15 Oscar HR 53000 2022-09-28
16 Paul Finance 69000 2021-10-05
17 Quinn IT 61000 2020-02-18
18 Rita HR 56000 2023-06-22
19 Sam Finance 78000 2019-07-11
20 Tina IT 75000 2021-08-03
GROUP BY with Aggregate
• SELECT Department, COUNT(*) AS EmpCount, AVG(Salary) AS AvgSalary
FROM Employee
GROUP BY Department;
WHERE Clause
• SELECT * FROM Employee
WHERE Department = 'IT' AND Salary > 60000;
HAVING Clause
• SELECT Department, COUNT(*) AS EmpCount
FROM Employee
GROUP BY Department
HAVING COUNT(*) > 3;
Nested SELECT
• SELECT Name, Salary FROM Employee
WHERE Salary > (SELECT AVG(Salary) FROM Employee);
INNER JOIN Example
• SELECT [Link], [Link] FROM Employee E
INNER JOIN Department D ON [Link] = [Link];
LEFT OUTER JOIN Example
• SELECT [Link], [Link] FROM Employee E
LEFT JOIN Department D ON [Link] = [Link];
UNION Example
• SELECT Name FROM Employee WHERE Department = 'IT'
UNION
SELECT Name FROM Employee WHERE Department = 'HR';

You might also like