ORACLE 数据库 表连接 使用加号(+)

数据库中多表连接是经常用到的,主要有内连接和外连接。

1. 内连接 (inner join)
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo
FROM Persons
INNER JOIN Orders
ON Persons.Id_P=Orders.Id_P
ORDER BY Persons.LastName

上面的等同于:

SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo
FROM Persons, Orders
WHERE Persons.Id_P = Orders.Id_P 

2. 外连接
1. 左外关联(LEFT JOIN ON)
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo
FROM Persons
LEFT JOIN Orders
ON Persons.Id_P=Orders.Id_P
ORDER BY Persons.LastName

上面的等同于:

SELECT Persons.LastName, Persons.FirstName,Orders.OrderNo
FROM Persons,Orders WHERE Persons.Id_P=Orders.Id_P(+) ORDER BY Persons.LastName

2. 右外关联(RIGHT JOIN ON)
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo
FROM Persons
RIGHT JOIN Orders
ON Persons.Id_P=Orders.Id_P
ORDER BY Persons.LastName

上面的代码等同于:

SELECT Persons.LastName, Persons.FirstName,Orders.OrderNo
FROM Persons,Orders WHERE Persons.Id_P(+) =Orders.Id_P ORDER BY Persons.LastName

3. 全外关联(FULL JOIN ON)
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo
FROM Persons
FULL JOIN Orders
ON Persons.Id_P=Orders.Id_P
ORDER BY Persons.LastName

说简单点就是那个表的数据要全部显示出来,那么加号放另一边

注意:这个加号的语法只适合用在oracle数据库中

你可能感兴趣的:(数据库基础)