For solving the above question we need to create two tables (EMPLOYEE , DEPARTMENT)
create table employee
(
empid number(5) primary key,
empname varchar2(50),
salary number(10,2),
Grade number(1),
deptno number(3) references department(deptno),
location varchar2(50),
desig varchar(20)
);
create table department
(
deptno number(3) primary key,
deptname varchar(50)
);
Then Insert few records in Employee and Department table.
EMPLOYEE
| EMPID | EMPNAME | SALARY | GRADE | DEPTNO | LOCATION | DESIG |
| 1 | AMIT SEN | 10000 | 1 | 1 | BHOPAL | MANAGER |
| 2 | RAMESH THAKUR | 11000 | 2 | 1 | BHOPAL | CLERK |
| 3 | RAKESH | 12000 | 1 | 1 | INDORE | CLERK |
| 4 | SUMIT SAKET | 9000 | 3 | 2 | BHOPAL | CLERK |
| 5 | AMIT SEN | 11000 | 2 | 2 | BHOPAL | MANAGER |
| 6 | AMIT SEN | 12000 | 2 | 5 | INDORE | CLERK |
| 7 | AMIT SEN | 15000 | 1 | 6 | INDORE | MANAGER |
DEPARTMENT
| DEPTNO | DEPTNAME |
| 1 | SALES |
| 2 | PRODUCTION |
| 3 | PURCHASE |
| 4 | MARKETING |
| 5 | ACCOUNTS |
| 6 | HR |
| 7 | ADMIN |
SQL :
select e.empname, d.deptno, d.deptname from department d , employee e
where d.deptno=e.deptno;
RESULT :
| EMPNAME | DEPTNO | DEPTNAME |
| AMIT SEN | 1 | SALES |
| RAMESH THAKUR | 1 | SALES |
| RAKESH | 1 | SALES |
| SUMIT SAKET | 2 | PRODUCTION |
| AMIT SEN | 2 | PRODUCTION |
| AMIT SEN | 5 | ACCOUNTS |
| AMIT SEN | 6 | HR |

No comments:
Post a Comment