SQL> select * from dept;
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SQL> select DNAME,LOC FROM DEPT
2 WHERE DEPTNO=(SELECT DEPTNO FROM EMP WHERE ENAME ='KING');
DNAME LOC
-------------- -------------
ACCOUNTING NEW YORK
SQL> SELECT ENAME FROM EMP
2 WHERE DEPTNO = (SELECT DEPTNO FROM DEPT WHERE LOC='CHICAGO');
ENAME
----------
ALLEN
WARD
MARTIN
BLAKE
TURNER
JAMES
6 rows selected.
SQL> SELECT ENAME, SAL FROM EMP
2 WHERE DEPTNO=(SELECT DEPTNO FROM DEPT WHERE DNAME='SALES');
ENAME SAL
---------- ----------
ALLEN 1600
WARD 1250
MARTIN 1250
BLAKE 2850
TURNER 1500
JAMES 950
6 rows selected.
SQL> SELECT * FROM EMP
2 WHERE DEPTNO=(SELECT DEPTNO FROM EMP WHERE ENAME='SMITH') AND
3 SAL>(SELECT SAL FROM EMP WHERE ENAME ='ADAMS') AND
4 JOB=(SELECT JOB FROM EMP WHERE ENAME='MILLER') AND
5 DEPTNO=(SELECT DEPTNO FROM DEPT WHERE LOC='BOSTON');
no rows selected
SQL> SELECT * FROM EMP
2 WHERE JOB =(SELECT JOB FROM EMP WHERE ENAME='MILLER') AND
3 DEPTNO=(SELECT DEPTNO FROM DEPT WHERE LOC='NEW YORK');
EMPNO ENAME JOB MGR HIREDATE SAL COMM
DEPTNO
---------- ---------- --------- ---------- --------- ---------- ----------
----------
7934 MILLER CLERK 7782 23-JAN-82 1300
10
SQL> SELECTB COUNT(*) FROM EMP
SP2-0734: unknown command beginning "SELECTB CO..." - rest of line ignored.
SQL> GROUP BY DEPTNO
SP2-0734: unknown command beginning "GROUP BY D..." - rest of line ignored.
SQL>
SQL>
SQL>
SQL>
SQL> SELECT COUNT(*) FROM EMP
2 GROUP BY DEPTNO
3 ORDER BY DEPTNO ASC;
COUNT(*)
----------
SQL> ED
Wrote file afiedt.buf
1 SELECT COUNT(*) FROM EMP
2 GROUP BY DEPTNO
3* ORDER BY DEPTNO DESC
SQL> /
COUNT(*)
----------
SQL> STOP SPOOL
SP2-0042: unknown command "STOP SPOOL" - rest of line ignored.
SQL>