Database Oracle Intensive Practice multi-table query

Source: Internet
Author: User
Tags dname

1. List the names of all employees and their immediate superiors

Select a.ename,a.mgr,b.ename,b.empno from emp a,emp b where a.mgr=b.empno (+);

2. List the name of the department and the employees of those departments, together with the departments that do not have employees

Select dept.deptno,dname,ename from Emp,dept where Emp.deptno (+) =dept.deptno;

3. Show employee names for all departments in "NEW YORK" (Dept table Loc Field)

Select e.ename from emp e,dept d Where e.deptno=d.deptno and d.loc= ' NEW YORK ';

4. Display the name of the employee "SMITH", Department name

Select e.ename,d.dname from emp e,dept D where E.deptno=d.deptno and E.ename= ' SMITH ';

5. Display the employee's name, department name, salary, pay scale (Salgrade table grade field), require salary scale greater than 4

Select e.ename,d.dname,e.sal,s.grade from emp e,dept d,salgrade s where E.deptno=d.deptno and e.sal between S.losal and S. Hisal and S.grade >4;

6. Display Employee name and manager name of employee "KING" and "FORD" management

Select e1.ename,e2.ename from EMP e1,emp E2 where E1.mgr=e2.empno and (e2.ename= ' KING ' or e2.ename= ' FORD ');

7. Display employee's name, working hours, manager's name, working hours: Working hours are earlier than his manager

Select e1.ename,e1.hiredate,e2.ename,e2.hiredate from EMP e1,emp E2 where E1.mgr=e2.empno and e1.hiredate< E2.hiredate;

Database Oracle Intensive Practice multi-table query

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.