0% found this document useful (0 votes)
239 views4 pages

Database Management System Practical No: 7 Aim: 1. To Perform Join Operations

The document discusses various SQL join operations - inner join, left join, right join, full outer join, and self join - and set operations - union, intersect, except. It also provides example syntax for each operation and poses a series of questions to write SQL queries that demonstrate performing different types of joins and set operations on sample tables.

Uploaded by

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

Database Management System Practical No: 7 Aim: 1. To Perform Join Operations

The document discusses various SQL join operations - inner join, left join, right join, full outer join, and self join - and set operations - union, intersect, except. It also provides example syntax for each operation and poses a series of questions to write SQL queries that demonstrate performing different types of joins and set operations on sample tables.

Uploaded by

Awaish Memon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Database Management System

Practical No : 7

Aim : 1. To perform join operations


2. Use set operators

SQL JOIN
An SQL JOIN clause is used to combine rows from two or more tables, based on a common field
between them.

SQL INNER JOIN

The INNER JOIN keyword selects all rows from both tables as long as there is a match between
the columns in both tables.

Syntax

SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name=table2.column_name;

SQL LEFT JOIN


The LEFT JOIN keyword returns all rows from the left table (table1), with the matching rows in
the right table (table2). The result is NULL in the right side when there is no match.

Syntax

SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON
table1.column_name=table2.column_name;

SQL RIGHT JOIN


The RIGHT JOIN keyword returns all rows from the right table (table2), with the matching rows
in the left table (table1). The result is NULL in the left side when there is no match.

Syntax
SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON
table1.column_name=table2.column_name;

SQL FULL OUTER JOIN


The FULL OUTER JOIN keyword returns all rows from the left table (table1) and from the right
table (table2).

The FULL OUTER JOIN keyword combines the result of both LEFT and RIGHT joins.

Syntax

SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON
table1.column_name=table2.column_name;

SQL SELF JOIN

SELECT  a.column_name, b.column_name...   
FROM table1  a, table1 b    
WHERE a.common_filed = b.common_field;  

SQL UNION :
The SQL UNION operator combines the result of two or more SELECT statements.
Syntax:
SELECT column_name(s) FROM table1
UNION
SELECT column_name(s) FROM table2;
SQL INTERSECT:
The SQL Intersect operator returns all the results which are common in two or more SELECT
statements.
Syntax:
SELECT column_name(s) FROM table1
Intersect
SELECT column_name(s) FROM table2;

SQL EXCEPT:
The SQL Except operator returns all the results which are in the result of first but not in the
result of second SELECT statement (Set-Difference).
Syntax:
SELECT column_name(s) FROM table1
Except
SELECT column_name(s) FROM table2;

Write SQL to answer following questions:


Create one table department.
Dept_no Dname Location
30 ACCOUNTING NEW YORK
60 RESEARCH DALLAS
90 SALES CHICAGO
110 MARKETING BOSTON

1) Display the common jobs from department number 90 and 60.


2) Display the unique jobs found in department number 90 and 60.
3) Display the jobs which are in dept no 90 but not in 30.
4) Display those employees who are working in the same dept with their
manager.
5) Display the name of the employees who are working as a Accountant or IT
and joined the company before 31-dec-2014.
6) Display employee name, job, deptname, location for all, who are working
as managers.
7) Display those employees whose manager names is ‘Steven’.
8) Display emp number and salary of ‘Steven’ if his Sal is equal to highest
Sal of his department.
9) List employees who is not working as a ‘CLERK’ (Sort on salary).
10) Display employees who are without manager.
11) Display the name of those employees who are getting highest salary
in the organization.
12) Display the name of those employees who are getting second
highest salary in the organization.
13) Display those employees whose salary is equal to average of
maximum and minimum.
14) Display the name of the department along with count of employees
where count greater than 3.
15) Display dname where at least 2 employees are working.
16) Display name of those managers whose salary is more than average
salary of company.
17) Find out the top 3 earner of company.
18) Find out the last 3(least) earner of the company?
19) Display employee name, his job, his dept name, his manager name,
his sal and arrange it based on salary.
20) List the emps who are not working in sales dept.
21) Find jobwise salary average.
22) Find the name of department taking maximum salary.
23) Find name of department taking minimum salary.

You might also like