Oracle multi-Table query, oracle

Source: Internet
Author: User

Oracle multi-Table query, oracle

To query multiple tables, we must first avoid Cartesian sets. To avoid Cartesian sets, the query conditions should not be less than the number of tables-1.
1. Display employee name, employee salary, and employee's department:

2. display the Department name, employee name, and salary with the department Number 10:

3. display the name, salary, and salary level of each employee:

4. display the employee name, employee salary, and department name, sorted by department

**

Self-connection

**

5. The name of FORD's superior leadership is displayed:

6. display the names, salaries, and department numbers of employees whose salaries are higher than those of all employees of Department 30:

7. display the name, salary, and department number of an employee whose salary is higher than that of any employee of Department 30:

8. query all employees who have the same department and position as SMITH:

9. Information showing all employees whose salaries are higher than the average salaries of their respective departments:

Idea: first identify the average salary and department number of each department, and then regard the query result as a table.

Select * from emp e, (select deptno, avg (sal) as avgsal from emp group by deptno) avg_sal where e. deptno = avg_sal.deptno and e. sal> avg_sal.avgsal;

**

Summary

**
When a subquery is used in the from clause, the subquery is treated as a view. Therefore, it is called an embedded view. When a subquery is used in the from clause, you must specify an alias for the subquery. the alias for the subquery does not use as. the alias for the column must use.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.