You are on page 1of 35

create table EMPLOYEE

(
EMPNO number(4),
ENAME varchar2(10),
JOB varchar(50)NOT NULL,
MGR varchar2(9),
HIREDATE date,
SAL number(7,2),
COMM number(7,2),
DEPTNO number(2),
PRIMARY KEY (EMPNO)
);

insert all
into EMPLOYEE
values(7839,'king','president','null',DATE '2001-9-17',50000,null,10)
into EMPLOYEE
values(7698,'Blake','manager',7839,DATE '2001-5-01',28500,null,30)
into EMPLOYEE
values(7782,'Clark','manager',7839,DATE '2001-6-09',24500,null,10)
into EMPLOYEE
values(7566,'Jones','manager',7839,DATE '2001-4-2',29750,null,20)
into EMPLOYEE
values(7654,'Martin','salesman',7698,DATE '2001-9-28',12500,14000,30)
into EMPLOYEE
values(7499,'Allen','salesman',7698,DATE '2001-2-20',16000,3000,30)
into EMPLOYEE
values(7844,'Turner','salesman',7698,DATE '2001-2-8',15000,0,30)
into EMPLOYEE
values(7900,'James','clerk',7698,DATE '2001-12-3',9500,null,30)
into EMPLOYEE
values(7521,'Ward','salesman',7698,DATE '2001-2-22',12500,5000,30)

into EMPLOYEE
values(7902,'Ford','analyst',7566,DATE '2001-12-3',30000,null,null)
into EMPLOYEE
values(7369,'Smith','clerk',7902,DATE '2000-12-17',8000,null,null)
into EMPLOYEE
values(7788,'Scott','analyst',7566,DATE '2002-12-09',30000,null,20)
into EMPLOYEE
values(7876,'adams','clerk',7788,DATE '2003-1-12',11000,null,20)
into EMPLOYEE
values(7934,'Miller','clerk',7782,DATE '2002-1-23',13000,null,null)
select * from dual;
select * from EMPLOYEE;

create table DEPARTMENT


(
DEPTNO number(2)NOT NULL,
DNAME varchar2(15),
LOC varchar2(15)
);

insert all
into DEPARTMENT values(10,'Accounting','NewDelhi')
into DEPARTMENT values(20,'Research','Bombay')
into DEPARTMENT values(30,'sales','Chennai')
into DEPARTMENT values(40,'operation','kolkata')
select * from dual;
select * from DEPARTMENT;

create table SALARYGRADE


(
GRADE number(1),
LOSAL number(7,2),

HISAL number(7,2)
);

insert all
into SALARYGRADE values(1,7000,12000)
into SALARYGRADE values(2,12001,14000)
into SALARYGRADE values(3,14001,20000)
into SALARYGRADE values(4,20001,30000)
into SALARYGRADE values(5,30001,99999)
SELECT * from dual;

SELECT * from SALARYGRADE;

Q2.

WAQ to display Employee Number, Job, Sal from Employee Table

ANS:

SQL> select EMPNO "Employee Number",JOB "Job",SAL "Sal" from EMPLOYEE;

Employee Number Job

Sal

--------------- --------- ---------7839 President

50000

7698 Manager

28500

7782 Manager

24500

7566 Manager

29750

7654 Salesman

12500

7499 Salesman

16000

7844 Salesman

15000

7900 Clerk
7521 Salesman

9500
12500

7902 Analyst

30000

7369 Clerk

8000

Employee Number Job

Sal

--------------- --------- ---------7788 Analyst

30000

7876 Clerk

11000

7934 Clerk

13000

14 rows selected.

Q3.

WAQ to display all the details of the Employees

ANS:

SQL> select * from EMPLOYEE;

EMPNO ENAME

JOB

MGR

HIREDATE

SAL

COMM

---------- ---------- --------- --------- --------- ---------- ---------DEPTNO


---------7839 King

President

17-NOV-01

50000

10

7698 Blake

Manager 7839

01-MAY-01

28500

Manager 7839

09-JUN-01

24500

30

7782 Clark
10

EMPNO ENAME

JOB

MGR

HIREDATE

SAL

COMM

---------- ---------- --------- --------- --------- ---------- ---------DEPTNO


---------7566 Jones

Manager 7839

02-APR-01

29750

20

7654 Martin

Salesman 7698

28-SEP-01

12500

14000

30

7499 Allen

Salesman 7698

20-FEB-01

16000

3000

HIREDATE

SAL

COMM

15000

30

EMPNO ENAME

JOB

MGR

---------- ---------- --------- --------- --------- ---------- ---------DEPTNO


---------7844 Turner

Salesman 7698

08-FEB-01

30

7900 James

Clerk

7698

03-DEC-01

9500

30

7521 Ward

Salesman 7698

22-FEB-01

12500

5000

HIREDATE

SAL

COMM

30

EMPNO ENAME

JOB

MGR

---------- ---------- --------- --------- --------- ---------- ---------DEPTNO


---------7902 Ford

Analyst 7566

03-DEC-01

30000

7369 Smith

Clerk

7788 Scott

7902

17-DEC-00

8000

Analyst 7566

09-DEC-02

30000

20

EMPNO ENAME

JOB

MGR

HIREDATE

SAL

---------- ---------- --------- --------- --------- ---------- ---------DEPTNO


---------7876 Adams

Clerk

7788

12-JAN-03

11000

20

7934 Miller

Clerk

7782

23-JAN-02

13000

14 rows selected.

Q4.

WAQ to display distinct Jobs of the Employees

ANS:

SQL> select distinct JOB from EMPLOYEE;

JOB
--------Manager
Clerk

COMM

Analyst
President
Salesman

Q5.

WAQ to display all Jobs of Employees using ALL keyword

ANS:

SQL> select all JOB from EMPLOYEE;

JOB
--------President
Manager
Manager
Manager
Salesman
Salesman
Salesman
Clerk
Salesman
Analyst
Clerk

JOB
--------Analyst
Clerk
Clerk

14 rows selected.

Q6.

WAQ to display the Names, Numbers and Salaries added with their
commissions from Employees Table

ANS:

SQL> select ENAME "Names",EMPNO "Numbers", SAL+nvl(COMM,0)


"Salary+Commission"
2 from EMPLOYEE;

Names

Numbers Salary+Commission

---------- ---------- ----------------King

7839

50000

Blake

7698

28500

Clark

7782

24500

Jones

7566

29750

Martin

7654

26500

Allen

7499

19000

Turner

7844

15000

James

7900

9500

Ward

7521

17500

Ford

7902

Smith

7369

Names

30000
8000

Numbers Salary+Commission

---------- ---------- ----------------Scott

7788

Adams
Miller

7876
7934

30000
11000
13000

14 rows selected.

Q7.

Show the structure of the three relations

ANS:

SQL> desc EMPLOYEE;


Name

Null?

Type

----------------------------------------- -------- ----------------------------

EMPNO

NOT NULL NUMBER(4)

ENAME
JOB

VARCHAR2(10)
NOT NULL VARCHAR2(9)

MGR

VARCHAR2(9)

HIREDATE
SAL

DATE
NUMBER(7,2)

COMM

NUMBER(7,2)

DEPTNO

NUMBER(2)

SQL> desc DEPARTMENT;


Name

Null?

Type

----------------------------------------- -------- ----------------------------

DEPTNO

NOT NULL NUMBER(2)

DNAME
LOC

VARCHAR2(15)
VARCHAR2(15)

SQL> desc SALARYGRADE;


Name

Null?

Type

----------------------------------------- -------- ----------------------------

GRADE

NUMBER(1)

LOSAL

NUMBER(7,2)

HISAL

NUMBER(7,2)

Q8.

Display the Salaries of the Employees before and after an increment of


15 % with their names

ANS:

SQL> select ENAME "Emp Name",SAL "Salary(Initial)",


2 1.15*SAL "Salary(after 15% Increase)" from EMPLOYEE;

Emp Name Salary(Initial) Salary(after 15% Increase)


---------- --------------- -------------------------King

50000

57500

Blake

28500

32775

Clark

24500

28175

Jones

29750

34212.5

Martin

12500

14375

Allen

16000

18400

Turner

15000

17250

James

9500

10925

Ward

12500

14375

Ford
Smith

30000

34500

8000

9200

Employee N Salary(Initial) Salary(after 15% Increase)


---------- --------------- -------------------------Scott

30000

Adams
Miller

11000
13000

34500
12650
14950

14 rows selected.

Q9.

WAQ to display the annual salary of Employees with their names and

numbers
ANS:

SQL> select EMPNO "Employee Number",ENAME "Emp Name",


2 SAL*12 "Annual Salary" from EMPLOYEE;

Employee Number Emp Name Annual Salary


--------------- ---------- ------------7839 King

600000

7698 Blake

342000

7782 Clark

294000

7566 Jones

357000

7654 Martin

150000

7499 Allen

192000

7844 Turner

180000

7900 James

114000

7521 Ward

150000

7902 Ford
7369 Smith

360000
96000

Employee Number Employee N Annual Salary


--------------- ---------- ------------7788 Scott
7876 Adams
7934 Miller

360000
132000
156000

14 rows selected.

Q10. WAQ to display the details of the employees and default values
(In place of Null values of commission use nvl function to show 0 )
ANS:

SQL> select EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,nvl(COMM,0)


"COMM",DEPTNO
2 from EMPLOYEE;

EMPNO ENAME

JOB

MGR

HIREDATE

SAL

COMM

---------- ---------- --------- --------- --------- ---------- ---------DEPTNO


---------7839 King

President

17-NOV-01

50000

10

7698 Blake

Manager 7839

01-MAY-01

28500

Manager 7839

09-JUN-01

24500

30

7782 Clark
10

EMPNO ENAME

JOB

MGR

HIREDATE

SAL

COMM

---------- ---------- --------- --------- --------- ---------- ---------DEPTNO


---------7566 Jones

Manager 7839

02-APR-01

29750

20

7654 Martin

Salesman 7698

28-SEP-01

12500

14000

30

7499 Allen
30

Salesman 7698

20-FEB-01

16000

3000

EMPNO ENAME

JOB

MGR

HIREDATE

SAL

COMM

15000

---------- ---------- --------- --------- --------- ---------- ---------DEPTNO


---------7844 Turner

Salesman 7698

08-FEB-01

30

7900 James

Clerk

7698

03-DEC-01

9500

30

7521 Ward

Salesman 7698

22-FEB-01

12500

5000

HIREDATE

SAL

COMM

30

EMPNO ENAME

JOB

MGR

---------- ---------- --------- --------- --------- ---------- ---------DEPTNO


---------7902 Ford

7369 Smith

7788 Scott

Analyst 7566

03-DEC-01

30000

7902

17-DEC-00

8000

Analyst 7566

09-DEC-02

30000

Clerk

20

EMPNO ENAME

JOB

MGR

HIREDATE

---------- ---------- --------- --------- --------- ---------- ---------DEPTNO


----------

SAL

COMM

7876 Adams

Clerk

7788

12-JAN-03

11000

20

7934 Miller

Clerk

7782

23-JAN-02

13000

14 rows selected.

Q11. WAQ to display the details of Employees in the following format.


JOHN WORKS AS MANAGER AND GETS RS 10000 EVERY MONTH
ANS:

SQL> select upper(ENAME)||' WORKS AS '||upper(JOB)||' AND GETS RS '||


2 SAL||' EVERY MONTH' "EMPLOYEE DETAILS" from EMPLOYEE;

EMPLOYEE DETAILS
--------------------------------------------------------------------------------

KING WORKS AS PRESIDENT AND GETS RS 50000 EVERY MONTH


BLAKE WORKS AS MANAGER AND GETS RS 28500 EVERY MONTH
CLARK WORKS AS MANAGER AND GETS RS 24500 EVERY MONTH
JONES WORKS AS MANAGER AND GETS RS 29750 EVERY MONTH
MARTIN WORKS AS SALESMAN AND GETS RS 12500 EVERY MONTH
ALLEN WORKS AS SALESMAN AND GETS RS 16000 EVERY MONTH
TURNER WORKS AS SALESMAN AND GETS RS 15000 EVERY MONTH
JAMES WORKS AS CLERK AND GETS RS 9500 EVERY MONTH
WARD WORKS AS SALESMAN AND GETS RS 12500 EVERY MONTH
FORD WORKS AS ANALYST AND GETS RS 30000 EVERY MONTH
SMITH WORKS AS CLERK AND GETS RS 8000 EVERY MONTH

EMPLOYEE DETAILS
--------------------------------------------------------------------------------

SCOTT WORKS AS ANALYST AND GETS RS 30000 EVERY MONTH


ADAMS WORKS AS CLERK AND GETS RS 11000 EVERY MONTH
MILLER WORKS AS CLERK AND GETS RS 13000 EVERY MONTH

14 rows selected.

Q12. WAQ to display the ename joined with the Job using || operator
ANS:

SQL> select ENAME||' '||JOB "Name joined with Job"


2 from EMPLOYEE;

Name joined with Job


-------------------King President
Blake Manager
Clark Manager
Jones Manager
Martin Salesman
Allen Salesman
Turner Salesman
James Clerk
Ward Salesman
Ford Analyst
Smith Clerk

Name joined with Job


--------------------

Scott Analyst
Adams Clerk
Miller Clerk

14 rows selected.

Q13. Display the names of employees having salary > 13000


ANS:

SQL> select ENAME from EMPLOYEE where SAL>13000;

ENAME
---------King
Blake
Clark
Jones
Allen
Turner
Ford
Scott

8 rows selected.

Q14. Give a query to display the names of employees who are not Managers
ANS:

SQL> select ENAME from EMPLOYEE where JOB!='Manager';

ENAME

---------King
Martin
Allen
Turner
James
Ward
Ford
Smith
Scott
Adams
Miller

11 rows selected.

Q15. WAQ to display the names of Employees who are managers or analysts or
clerk using IN operator
ANS:

SQL> select ENAME from EMPLOYEE where JOB in('Manager','Analyst','Clerk');

ENAME
---------Blake
Clark
Jones
James
Ford
Smith
Scott
Adams

Miller

9 rows selected.

Q16. WAQ to display the names of employees who didnt get any commission
ANS:

SQL> select ENAME from EMPLOYEE where COMM IS NULL;

ENAME
---------King
Blake
Clark
Jones
James
Ford
Smith
Scott
Adams
Miller

10 rows selected.

Q17. WAQ to display the names, salaries and commission of employees who
dont
get commission
ANS:

SQL> select ENAME,SAL,nvl(COMM,0) "COMM" from EMPLOYEE


2 where COMM IS NULL;

ENAME

SAL

COMM

---------- ---------- ---------King

50000

Blake

28500

Clark

24500

Jones

29750

9500

30000

8000

30000

James
Ford
Smith
Scott
Adams
Miller

11000

13000

10 rows selected.

Q18. Select the names of employees whose salary is between 15000 and 20000
ANS:

SQL> select ENAME,SAL,COMM from EMPLOYEE where SAL


2 between 15000 and 20000;

ENAME

SAL

COMM

---------- ---------- ---------Allen


Turner

16000
15000

3000
0

Q19. WAQ to display the names of employees with their department names
ANS:

SQL> select e.ENAME,d.DNAME


2 from EMPLOYEE e natural join DEPARTMENT d;

ENAME

DNAME

---------- --------------King

Accounting

Blake

Sales

Clark

Accounting

Jones

Research

Martin

Sales

Allen

Sales

Turner

Sales

James

Sales

Ward

Sales

Scott

Research

Adams

Research

11 rows selected.

Q20. WAQ to display the names of employees with their salary grades
ANS:

SQL> select E.ENAME,S.GRADE


2 from EMPLOYEE E JOIN SALARYGRADE S
3 on E.SAL between S.LOSAL and S.HISAL;

ENAME

GRADE

---------- ---------Smith

James

Adams

Ward

Martin

Miller

Turner

Allen

Clark

Blake

Jones

ENAME

GRADE

---------- ---------Ford

Scott

King

14 rows selected.

Q21. Display the names of employees whose name starts with S


ANS:

SQL> select ENAME from EMPLOYEE where ENAME like 'S%';

ENAME
---------Smith
Scott

Q22. Display the names of employees whose name ends with D


ANS:

SQL> select ENAME from EMPLOYEE where ENAME like '%D';

no rows selected

Q23. Display the names of employees whose name holds the character O in
any place
ANS:

SQL> select ENAME from EMPLOYEE where ENAME


2 like 'O%' or ENAME like '%O%' or ENAME like '%O';

no rows selected

Q24. WAQ to display the names of employees in the order of their salary
ascending and descending separately
ANS:

SQL> select ENAME,SAL from EMPLOYEE


2 order by SAL asc;

ENAME

SAL

---------- ---------Smith

8000

James

9500

Adams

11000

Ward

12500

Martin

12500

Miller
Turner

13000
15000

Allen

16000

Clark

24500

Blake

28500

Jones

29750

ENAME

SAL

---------- ---------Ford

30000

Scott

30000

King

50000

14 rows selected.

SQL> select ENAME,SAL from EMPLOYEE


2 order by SAL desc;

ENAME

SAL

---------- ---------King

50000

Scott

30000

Ford

30000

Jones

29750

Blake

28500

Clark

24500

Allen

16000

Turner
Miller

15000
13000

Ward

12500

Martin

12500

ENAME

SAL

---------- ---------Adams

11000

James

9500

Smith

8000

14 rows selected.

Q25. Give a query to display the names of employees whose name has
only four characters
ANS:

SQL> select ENAME from EMPLOYEE


2 where length(ENAME)=4;

ENAME
---------King
Ward
Ford

Q26. WAQ to display the name, job, salary and hiredate of employees where
salary is between 10000 and 20000 in ascending order of their hiredate
ANS:

SQL> select ENAME,JOB,SAL,HIREDATE from EMPLOYEE


2 where SAL between 10000 and 20000
3 order by HIREDATE;

ENAME

JOB

SAL HIREDATE

---------- --------- ---------- --------Turner


Allen
Ward

Salesman
Salesman
Salesman

15000 08-FEB-01
16000 20-FEB-01
12500 22-FEB-01

Martin

Salesman

Miller

Clerk

Adams

Clerk

12500 28-SEP-01
13000 23-JAN-02
11000 12-JAN-03

6 rows selected.

Q27. WAQ to display the names of employees concatenated with their job and
use alias by NameJob and sort them using the alias name in
descending order
ANS:

SQL> select ENAME||JOB "NameJob" from EMPLOYEE


2 order by ENAME||JOB desc;

NameJob
------------------WardSalesman
TurnerSalesman
SmithClerk
ScottAnalyst
MillerClerk
MartinSalesman
KingPresident
JonesManager
JamesClerk
FordAnalyst
ClarkManager

NameJob
------------------BlakeManager

AllenSalesman
AdamsClerk

14 rows selected.

Q28. Display the names, number, job, salary of employees who do not have
manager
ANS:

SQL> select ENAME,EMPNO,JOB,SAL from EMPLOYEE


2 where MGR IS NULL;

ENAME

EMPNO JOB

SAL

---------- ---------- --------- ---------King

7839 President

50000

Q29. Write a query to perform a calculation of the expression


4*5+6/2
ANS:

SQL> select 4*5+6/2 from DUAL;

4*5+6/2
---------23

Q30. Display todays Date


ANS:

SQL> select SYSDATE "Date"


2 from DUAL;

Date
--------05-APR-10

Q31. Display the remaining days of this month


ANS:

Q32. WAQ to display the sum, average, standard deviation, variance,


no. of records, minimum, maximum of salary in employee table using alias
ANS:

SQL> select sum(sal) "Sum",avg(sal) "Average",avg(sal*sal)-(avg(sal)*avg(sal)) "


Variance",sqrt(avg(sal*sal)-(avg(sal)*avg(sal))) "Stand Dev",count(empno) "No of
records",min(sal) "Min Salary",max(sal) "Max Salary" from employee;

Sum

Average Variance Stand Dev No of records Min Salary Max Salary

---------- ---------- ---------- ---------- ------------- ---------- ---------290250 20732.1429 129843431 11394.8862

14

8000

50000

Q33. Display the minimum and maximum salary in each job


ANS:

SQL> select JOB,min(SAL) "Min Sal",max(SAL) "Max Sal" from employee


2 group by job;

JOB

Min Sal

Max Sal

--------- ---------- ---------Manager

24500

Clerk

8000

Analyst

30000

President
Salesman

29750
13000

50000
12500

30000
50000
16000

Q34. Display the no. of employees in each department in ascending order


of the count of the employees
ANS:

SQL> select DEPTNO,count(EMPNO) "No of Emploees"


2 from employee where DEPTNO IS NOT NULL
3 group by DEPTNO
4 order by DEPTNO;

DEPTNO No of Emploees
---------- -------------10

20

30

Q35. Display the no. of employees job wise within department wise
ANS:

SQL> select DEPTNO,JOB,count(EMPNO)


2 from EMPLOYEE where DEPTNO IS NOT NULL
3 group by DEPTNO,JOB
4 order by DEPTNO,JOB;

DEPTNO JOB

COUNT(EMPNO)

---------- --------- -----------10 Manager

10 President
20 Analyst
20 Clerk

1
1
1

20 Manager
30 Clerk

1
1

30 Manager

30 Salesman

8 rows selected.

Q36. Show the number of managers in each department


ANS:

SQL> select DEPTNO,count(JOB) "Manager"


2 from EMPLOYEE where JOB='Manager'
3 group by DEPTNO
4 order by DEPTNO;

DEPTNO

Manager

---------- ---------10

20

30

Q37. Display the names of departments which consist more than 4 employees
ANS:

SQL> select D.DNAME


2 from EMPLOYEE E natural join DEPARTMENT D
3 group by D.DNAME
4 having count(E.EMPNO)>4;

DNAME
--------------Sales

Q38. WAQ to display the department number and salary difference in each
department where department is not 40 and difference is > 5000 (show
in ascending order of the difference)
ANS:

SQL> select DEPTNO,max(SAL)-min(SAL) "Salary Difference"


2 from EMPLOYEE group by DEPTNO
3 having (max(SAL)-min(SAL))>5000 and DEPTNO!=40
4 order by max(SAL)-min(SAL) asc;

DEPTNO Salary Difference


---------- ----------------30

19000

20

19000

10

25500

Q39. Show which positions are paid a higher than average salary
ANS:

SQL> select ENAME from EMPLOYEE


2 where SAL>(select avg(SAL) from EMPLOYEE);

ENAME
---------King
Blake
Clark
Jones
Ford
Scott

6 rows selected.

Q40. Select second maximum salary from employee


ANS:

SQL> select distinct SAL from EMPLOYEE


2 where SAL=(select max(SAL) from EMPLOYEE where SAL<
3 (select max(SAL) from EMPLOYEE));

SAL
---------30000

Q41. Select the 4th minimum salary from employee


ANS:

SQL> select distinct SAL from EMPLOYEE


2 where SAL=(select min(SAL) from EMPLOYEE where SAL>
3 (select min(SAL) from EMPLOYEE where SAL>
4 (select min(SAL) from EMPLOYEE where SAL>

5 (select min(SAL) from EMPLOYEE))));

SAL
---------12500

Q42. Select the name of employees who are getting minimum salary in
employee table
ANS:

SQL> select ENAME from EMPLOYEE


2 where SAL=all(select min(SAL) from EMPLOYEE);

ENAME
---------Smith

Q43. Select the names of employees who are getting maximum salary in each
department
ANS:

SQL> select ENAME from EMPLOYEE


2 where SAL in(select max(SAL)from EMPLOYEE group by DEPTNO);

ENAME
---------King
Blake
Ford
Scott

Q44. Show details of those employees that have salary equal to any employees
of department
ANS:

SQL> select
E.EMPNO,E.ENAME,E.JOB,E.MGR,E.HIREDATE,E.COMM,E.SAL,E.DEPTNO
2 from EMPLOYEE E,EMPLOYEE D
3 where E.EMPNO!=D.EMPNO
4 and E.SAL=D.SAL and E.DEPTNO=D.DEPTNO;

EMPNO ENAME

JOB

MGR

HIREDATE

COMM

SAL

---------- ---------- --------- --------- --------- ---------- ---------DEPTNO


---------7521 Ward

Salesman 7698

22-FEB-01

5000

12500

Salesman 7698

28-SEP-01

14000

12500

30

7654 Martin
30

Q45. Show details of those employee that have salary more than or equal to
average salary
ANS:

SQL> select * from EMPLOYEE


2 where SAL in(select SAL from EMPLOYEE where SAL>=
3 (select avg(SAL) from EMPLOYEE));

EMPNO ENAME

JOB

MGR

HIREDATE

---------- ---------- --------- --------- --------- ---------- ----------

SAL

COMM

DEPTNO
---------7839 King

President

17-NOV-01

50000

10

7698 Blake

Manager 7839

01-MAY-01

28500

Manager 7839

09-JUN-01

24500

30

7782 Clark
10

EMPNO ENAME

JOB

MGR

HIREDATE

SAL

COMM

---------- ---------- --------- --------- --------- ---------- ---------DEPTNO


---------7566 Jones

Manager 7839

02-APR-01

29750

20

7902 Ford

Analyst 7566

03-DEC-01

30000

7788 Scott

Analyst 7566

09-DEC-02

30000

20

6 rows selected.

Q46. Select the details of departments that have at least one employee
ANS:

SQL> select distinct(DEPTNO),DNAME,LOC


2 from EMPLOYEE natural join DEPARTMENT;

DEPTNO DNAME

LOC

---------- --------------- --------------10 Accounting


30 Sales
20 Research

New Delhi
Chennai
Bombay

You might also like