0% found this document useful (0 votes)
14 views5 pages

Assignment 18

The document contains multiple SQL queries and their results related to employee and department data. It includes selections of employee names and locations, salary calculations, and filtering based on department names and hire dates. Additionally, it shows errors encountered during query execution due to syntax issues.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views5 pages

Assignment 18

The document contains multiple SQL queries and their results related to employee and department data. It includes selections of employee names and locations, salary calculations, and filtering based on department names and hire dates. Additionally, it shows errors encountered during query execution due to syntax issues.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

SQL> select ename,loc

2 from emp,dept
3 where emp.deptno=dept.deptno;

ENAME LOC
---------- -------------
SMITH DALLAS
ALLEN CHICAGO
WARD CHICAGO
JONES DALLAS
MARTIN CHICAGO
BLAKE CHICAGO
CLARK NEW YORK
SCOTT DALLAS
KING NEW YORK
TURNER CHICAGO
ADAMS DALLAS

ENAME LOC
---------- -------------
JAMES CHICAGO
FORD DALLAS
MILLER NEW YORK

14 rows selected.

SQL> set pages 100 lines 100


SQL> select ename,loc
2 from emp,dept
3 where emp.deptno=dept.deptno;

ENAME LOC
---------- -------------
SMITH DALLAS
ALLEN CHICAGO
WARD CHICAGO
JONES DALLAS
MARTIN CHICAGO
BLAKE CHICAGO
CLARK NEW YORK
SCOTT DALLAS
KING NEW YORK
TURNER CHICAGO
ADAMS DALLAS
JAMES CHICAGO
FORD DALLAS
MILLER NEW YORK

14 rows selected.

SQL> select DNAME,SAL FROM EMP,DEPT


2 where emp.deptno=dept.deptno AND DNAME IN 'ACCOUNTING';

DNAME SAL
-------------- ----------
ACCOUNTING 2450
ACCOUNTING 5000
ACCOUNTING 1300
SQL> select DNAME,SAL*12
2 FROM EMP,DEPT
3 where emp.deptno=dept.deptno AND SAL>2340;

DNAME SAL*12
-------------- ----------
RESEARCH 35700
SALES 34200
ACCOUNTING 29400
RESEARCH 36000
ACCOUNTING 60000
RESEARCH 36000

6 rows selected.

SQL> select DNAME,ENAME


2 FROM EMP,DEPT
3 where emp.deptno=dept.deptno AND DNAME
4 LIKE '%A%';

DNAME ENAME
-------------- ----------
RESEARCH SMITH
SALES ALLEN
SALES WARD
RESEARCH JONES
SALES MARTIN
SALES BLAKE
ACCOUNTING CLARK
RESEARCH SCOTT
ACCOUNTING KING
SALES TURNER
RESEARCH ADAMS
SALES JAMES
RESEARCH FORD
ACCOUNTING MILLER

14 rows selected.

SQL> SELECT DNAME,MGR


2 FROM EMP,DEPT
3 WHERE EMP.DEPTNO=DEPT.DEPTNO
4 AND MGR IN(SELECT EMPNO FROM EMP
5 WHERE EMPNO IN 7839);

DNAME MGR
-------------- ----------
RESEARCH 7839
SALES 7839
ACCOUNTING 7839

SQL> SELECT DNAME,HIREDATE


2 FROM EMP,DEPT
3 WHERE EMP.DEPTNO=DEPT.DEPTNO
4 AND HIREDATE>='01-AN-1983' AND DNAME IN('ACCOUNTING','RESEARCH');
AND HIREDATE>='01-AN-1983' AND DNAME IN('ACCOUNTING','RESEARCH')
*
ERROR at line 4:
ORA-01843: not a valid month
SQL> SELECT DNAME,HIREDATE
2 FROM EMP,DEPT
3 WHERE EMP.DEPTNO=DEPT.DEPTNO
4 AND HIREDATE>='01-JAN-1983' AND DNAME IN('ACCOUNTING','RESEARCH');

DNAME HIREDATE
-------------- ---------
RESEARCH 19-APR-87
RESEARCH 23-MAY-87

SQL> SELECT ENAME,DNAME


2 FROM EMP,DEPT
3 WHERE EMP.DEPTNO=DEPT.DEPTNO
4 AND COMM IS NOT NULL AND DEPTNO IN(10,30);
AND COMM IS NOT NULL AND DEPTNO IN(10,30)
*
ERROR at line 4:
ORA-00918: column ambiguously defined

SQL>
SQL> SELECT DNAME,EMPNO
2 FROM EMP,DEPT
3 WHERE EMP.DEPTNO=DEPT.DEPTNO
4 AND EMPNO IN(7839,7902) AND DNAME IN 'NEWYORK');
AND EMPNO IN(7839,7902) AND DNAME IN 'NEWYORK')
*
ERROR at line 4:
ORA-00933: SQL command not properly ended

SQL> SELECT DNAME,EMPNO


2 FROM EMP,DEPT
3 WHERE EMP.DEPTNO=DEPT.DEPTNO
4 AND EMPNO IN(7839,7902) AND DNAME IN 'NEWYORK';

no rows selected

SQL> SELECT DNAME,EMPNO


2 FROM EMP,DEPT
3 WHERE EMP.DEPTNO=DEPT.DEPTNOAND EMPNO IN(7839,7902) AND
4 LOC IN 'NEWYORK';
WHERE EMP.DEPTNO=DEPT.DEPTNOAND EMPNO IN(7839,7902) AND
*
ERROR at line 3:
ORA-00933: SQL command not properly ended

SQL> SELECT DNAME,EMPNO


2 FROM EMP,DEPT
3 WHERE EMP.DEPTNO=DEPT.DEPTNO SELECT DNAME,EMPNO
4 FROM EMP,DEPT
5
SQL>
SQL> SELECT DNAME,EMPNO
2 FROM EMP,DEPT
3 WHERE EMP.DEPTNO=DEPT.DEPTNO SELECT DNAME,EMPNO
4 AND EMPNO IN(7839,7902) AND LOC IN 'NEWYORK';
WHERE EMP.DEPTNO=DEPT.DEPTNO SELECT DNAME,EMPNO
*
ERROR at line 3:
ORA-00933: SQL command not properly ended

SQL> SELECT DNAME,EMPNO


2 FROM EMP,DEPT
3 WHERE EMP.DEPTNO=DEPT.DEPTNO
4 AND EMPNO IN(7839,7902) AND LOC IN 'NEWYORK';

no rows selected

SQL> SET PAGES 100 LINES 100


SQL> SELECT * FROM EMP;

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 19-APR-87 3000
20
7839 KING PRESIDENT 17-NOV-81 5000
10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0
30
7876 ADAMS CLERK 7788 23-MAY-87 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

14 rows selected.

SQL> SELECT *FROM DEPT;

DEPTNO DNAME LOC


---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON

SQL>

You might also like