Oracle table connection method

Source: Internet
Author: User


ORACLE 8i, 9i table connection method. Normal equal connections:
Select * from a, B where a. id = B. id;
This is an internal connection.

For external connections:
"(+)" Can be used in Oracle, and 9i can use LEFT/RIGHT/full outer join.

Left outer join: LEFT OUTER JOIN
SELECT e. last_name, e. department_id, d. department_name
FROM employees e
Left outer join orders ments d
ON (e. department_id = d. department_id );

Equivalent
SELECT e. last_name, e. department_id, d. department_name
FROM employees e, departments d
WHERE e. department_id = d. department_id (+)
Result: Records of all employees and their respective departments, including records of employees who do not have the corresponding department number department_id.

Right outer join: RIGHT OUTER JOIN
SELECT e. last_name, e. department_id, d. department_name
FROM employees e
Right outer join orders ments d
ON (e. department_id = d. department_id );

Equivalent
SELECT e. last_name, e. department_id, d. department_name
FROM employees e, departments d
WHERE e. department_id (+) = d. department_id
Result: Records of all employees and their respective departments, including records of departments without any employees.

Full outer join: FULL OUTER JOIN
SELECT e. last_name, e. department_id, d. department_name
FROM employees e
Full outer join orders ments d
ON (e. department_id = d. department_id );
Result: Records of all employees and their respective departments, including employee records without the corresponding department number department_id and department records without any employees.
ORACLE8i is a syntax that does not directly support full outer join. That is to say, you cannot add (+) to both the left and right tables. The following is the complete Outer Join syntax that can be referenced in ORACLE8i.
Select t1.id, t2.id from table1 t1, table t2 where t1.id = t2.id (+)
Union
Select t1.id, t2.id from table1 t1, table t2 where t1.id (+) = t2.id

Connection Type Definition Illustration Example
Internal Connection Connect only matched rows Select A. c1, B. c2 from A join B on A. c3 = B. c3;
Left Outer Join Contains all rows in the left table (no matter whether the table on the right has rows that match them) and all matched rows in the right table Select A. c1, B. c2 from A left join B on A. c3 = B. c3;
Outer right connection Contains all rows in the right table (no matter whether the table on the left has rows that match them) and all matched rows in the left table Select A. c1, B. c2 from A right join B on A. c3 = B. c3;
All external connections Contains all rows in the left and right tables, regardless of whether the tables on the other side have rows matching them. Select A. c1, B. c2 from A full join B on A. c3 = B. c3;
(Theta) Connection Use conditions other than equivalence to match rows in the left and right tables
Select A. c1, B. c2 from A join B on A. c3! = B. c3;
Cross join Generate Cartesian Product -- it does not use any matching or selection conditions, but directly matches each row in a data source with each row in another data source.   Select A. c1, B. c2 from A, B;

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.