100% found this document useful (1 vote)
153 views2 pages

SQL: Join, Aliases and Set Operators, Union, Intersect, Minus and NESTED Queries

This document discusses SQL queries using joins, aliases, set operators, and nested queries. It provides 4 examples of SQL queries: [1] a query that displays employee names, departments, and other employees in the same department; [2] a query that displays employee details hired after a certain date; [3] a query that displays employee details hired before their managers; [4] a query that displays employee names, salaries, and managers whose manager is a certain person and salary is over a certain amount.

Uploaded by

asdf
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
100% found this document useful (1 vote)
153 views2 pages

SQL: Join, Aliases and Set Operators, Union, Intersect, Minus and NESTED Queries

This document discusses SQL queries using joins, aliases, set operators, and nested queries. It provides 4 examples of SQL queries: [1] a query that displays employee names, departments, and other employees in the same department; [2] a query that displays employee details hired after a certain date; [3] a query that displays employee details hired before their managers; [4] a query that displays employee names, salaries, and managers whose manager is a certain person and salary is over a certain amount.

Uploaded by

asdf
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/ 2

LAB NO.

10

SQL: Join, Aliases and Set Operators, union, Intersect, Minus and NESTED
Queries

LAB TASK

1. Create a query that displays ename, deptno, and all enames of those employees
who work in the same department as a given employee. Give each column an
appropriate Label.

SELECT EMP.ENAME, DEPT.DNAME,EMP.DEPTNO FROM EMP INNER JOIN


DEPT ON DEPT.DEPTNO=EMP.DEPTNO ;

2. Create a query that displays enames, deptno, and hiredates of all employees
hired after employee MARTIN.
SELECT ENAME,DEPTNO,HIREDATE FROM EMP WHERE HIREDATE
<=(SELECT HIREDATE FROM EMP WHERE ENAME=’Sara’);

3. Create a query that displays enames, deptno, and hiredates for all employees
who were hired before their managers, alongwith their manager‘s names and
hiredates. Give the columns with appropriate labels.

Select E.ENAME ”Employees”,E.DEPTNO”1dept”,E.HIREDATE


” 1hiredate”,M.ENAME”MGR3”,E.HIREDATE”mgr hiredate”
From EMP E , EMP M
Where E.HIREDATE >M.HIREDATE AND E.EMPNO=M.MGR;

Write a query to display the enames, sal and mgr of every employee
whose mgr is KING and sal is greater than 800.
SELECT ENAME,SAL,MGR FROM EMP WHERE MGR=’7839’ AND SAL>800;

2. Write a query to display the empno, enames and salaries of all


employees who earn more than the average salary and work in a
department with any employee with a in their ename

4. SELECT ENAME,DEPTNO,SAL FROM EMP


5. WHERE SAL>(SELECT AVG(SAL) FROM EMP WHERE DEPTNO=DEPTNO AND ENAME
LIKE ‘%A%’);

2.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy