You are on page 1of 4

EMPNO ENAME JOB MGR HIREDATE SAL COMM

DEPTNO
---------- ---------- --------- ---------- --------- ---------- ----------
----------
7369 SMITH CLERK 7902 17-DEC-80 800
20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300
30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500
30
7566 JONES MANAGER 7839 02-APR-81 2975
20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400
30
7698 BLAKE MANAGER 7839 01-MAY-81 2850
30
7782 CLARK MANAGER 7839 09-JUN-81 2450
10
7788 SCOTT ANALYST 7566 09-DEC-82 3000
20
7839 KING PRESIDENT 17-NOV-81 5000
10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0
30
7876 ADAMS CLERK 7788 12-JAN-83 1100
20
7900 JAMES CLERK 7698 03-DEC-81 950
30
7902 FORD ANALYST 7566 03-DEC-81 3000
20
7934 MILLER CLERK 7782 23-JAN-82 1300
10

*****SELECT column_name1,column_name2 where column(arithmatic op) value

Q. Display the empluy whose working in 10 dept


A. SELECT ENAME from emp where DEPTNO=10

Q. Display the all clerk name and department


A. SQL> SELECT ENAME,DEPTNO from emp where JOB='CLERK';

ENAME DEPTNO
---------- ----------
SMITH 20
ADAMS 20
JAMES 30
MILLER 10

Q. Display 20 dept employ salary and name


A. SQL> SELECT ENAME,SAL from emp where DEPTNO='20';

ENAME SAL
---------- ----------
SMITH 800
JONES 2975
SCOTT 3000
ADAMS 1100
FORD 3000
Q. All Manager is working in which dept
A. SQL> SELECT DEPTNO from emp where JOB='MANAGER';

DEPTNO
----------
20
30
10

*****SELECT column_name
from table_name
where cond1 (and/or) cond2;***** (and when both the cond should be
true ,or when either can be true)

EG:- Display employee who is clerk and working in 10 dept


A. SQL> SELECT ENAME
2 from emp
3 where JOB='CLERK' and DEPTNO='10';

ENAME
----------
MILLER

Q. Display the name and dept who are working in 10 or 20 dept


A. SQL> SELECT ENAME,DEPTNO
2 from emp
3 where DEPTNO='10' or DEPTNO='20';

ENAME DEPTNO
---------- ----------
SMITH 20
JONES 20
CLARK 10
SCOTT 20
KING 10
ADAMS 20
FORD 20
MILLER 10

*****When used in only column IN operation is used******

EG;- SELECT ENAME,DEPTNO


2 from emp
3 where DEPTNO IN(10,20);
==>
ENAME DEPTNO
---------- ----------
SMITH 20
JONES 20
CLARK 10
SCOTT 20
KING 10
ADAMS 20
FORD 20
MILLER 10

Q. Display the employee whose salary is more than 1000 and working in 10 or 20 dept
A. SQL> SELECT ENAME
2 from emp
3 where SAL>1000 and DEPTNO IN(10,20);

ENAME
----------
JONES
CLARK
SCOTT
KING
ADAMS
FORD
MILLER

******In sql execution occurs from left to right, so the cond more imp is to be on
left******

******DUMMY TABLE

SELECT 'Ishi' from dual; (name display)

SELECT 2+2 from dual; (addition)

SELECT sysdate from dual; (date of the system)******

Q. Display the no of days from which the employees are working


A.
SELECT (sysdate-HIREDATE) from emp;

(SYSDATE-HIREDATE)
------------------
13686.7557
13621.7557
13619.7557
13580.7557
13401.7557
13551.7557
13512.7557
12964.7557
13351.7557
13421.7557
12930.7557
13335.7557
13335.7557
13284.7557

You might also like