Implementation of multi-table query in Oracle database

Source: Internet
Author: User
Tags dname join oracle database

A multiple-table query means getting the appropriate data from multiple tables.

(1) Cartesian product "The join condition is invalid or omitted, all rows of the two tables are connected, and the combination of all rows is returned (N*M)"

Sql> Select E.ename,d.dname from emp e,dept d;//Invalid

Sql> Select E.ename,d.dname from emp e,dept D

2 where e.ename= ' SCOTT ';/effective

(2) Equivalent connection (inner connection or simple connection)

The column values for a two-table join condition must be equal, typically such a connection contains a primary key and a foreign key

Sql> Select E.ename,d.dname from emp e,dept D

2 where E.deptno=d.deptno

3 and E.ename= ' SCOTT ';

(3) connections with more than two tables

Sql> CREATE TABLE Manager

2 AS

3 Select Ename,deptno,sal,job

4 from EMP; Create manager table

Sql> Select E.empno,m.ename,m.deptno,d.loc

2 from EMP E,manager m,dept D

3 where M.deptno=d.deptno

4 and M.ename=e.ename

5 and E.job=upper (' manager ');

(4) Non-equivalence connection "Using other connection operators"

Sql> Select E.empno,e.ename,e.sal,s.grade

2 from EMP E,salgrade s

3 where E.sal

4 between S.losal and Hisal;

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.