简体   繁体   English

SELECT * FROM tableA,tableB在哪里条件[+]

[英]SELECT * FROM tableA, tableB WHERE Conditions [+]

I have the following query 我有以下查询

SELECT * 
FROM tableA, tableB
WHERE Conditions [+]

What does this keyword Conditions[+] Stands for? 此关键字Condition [+]代表什么? How this query behaves as a outer join? 此查询如何表现为外部联接?

That is old Oracle Join syntax. 那是旧的Oracle Join语法。

SELECT * 
FROM tableA, tableB
WHERE Conditions [+] -- this should be tableA (+) = tableB

The positioning of the + sign denotes the JOIN syntax. +号的位置表示JOIN语法。

If you query was: 如果查询是:

SELECT * 
FROM tableA, tableB
WHERE tableA.id (+) = tableB.Id

Then it would be showing a RIGHT OUTER JOIN so the equivalent is: 然后它将显示一个RIGHT OUTER JOIN所以等效项是:

SELECT * 
FROM tableA
RIGHT OUTER JOIN tableB
   ON tableB.id = tableA.Id

If the + sign was on the other side then it would be a LEFT OUTER JOIN 如果+号在另一侧,则将是LEFT OUTER JOIN

SELECT * 
FROM tableA, tableB
WHERE tableA.id  = tableB.Id (+)

is equivalent to 相当于

SELECT * 
FROM tableA
LEFT OUTER JOIN tableB
   ON tableA.id = tableB.Id

I would advise using standard join syntax though. 我建议使用标准连接语法。

If you do not specify a + sign then it will be interpreted as an INNER JOIN 如果您未指定+号,那么它将被解释为INNER JOIN

SELECT * 
FROM tableA, tableB
WHERE tableA = tableB

it's equivalent is: 等效为:

SELECT * 
FROM tableA
INNER JOIN tableB
    ON tableA.id = tableB.id

A FULL OUTER JOIN would be written using two SELECT statements and a UNION : 将使用两个SELECT语句和一个UNION来编写FULL OUTER JOIN

SELECT * 
FROM tableA, tableB
WHERE tableA.id  = tableB.Id (+)
UNION
SELECT * 
FROM tableA, tableB
WHERE tableA.id (+) = tableB.Id 

It's equivalent is: 等效为:

SELECT * 
FROM tableA
FULL OUTER JOIN tableB
    ON tableA.id = tableB.id

Here is a tutorial that explains a lot of these: 这是一个教程,其中解释了很多这些:

Old Outer Join Syntax 旧的外部联接语法

It is not important how that behaves. 行为如何并不重要。 You should use the standard syntax for outer joins: 您应该对外部联接使用标准语法:

select *
from tableA left outer join
     tableB
     on . . .

The "(+)" syntax was introduced by Oracle before the standard syntax, and it is highly out of date. Oracle在标准语法之前引入了“(+)”语法,并且它已经过时了。

'Conditions' here just means what you're using to filter all this data. 这里的“条件”仅表示您用来过滤所有这些数据的内容。

LIke here's an example: 举个例子:

SELECT * 
FROM tableA, tableB
WHERE Name like '%Bob%'

would return names that have "Bob" anywhere inside. 将返回内部任何地方都带有“ Bob”的名称。

About outer joins, actually you'd use that in the FROM clause: 关于外部联接,实际上您可以在FROM子句中使用它:

So maybe 所以也许

SELECT * 
FROM tableA ta 
     OUTER JOIN tableB tb
     ON ta.name = tb.name
WHERE ta.age <> 10

and there where here is optional, by the way 顺便说一下,那里是可选的

I hate to just copy & paste an answer, but this sort of thing can be found pretty easily if you do a little searching... 我讨厌只复制并粘贴答案,但是如果您稍作搜索,就可以很容易地找到这种东西……

An outer join returns rows for one table, even when there are no matching rows in the other. 外部联接返回一个表的行,即使另一表中没有匹配的行也是如此。 You specify an outer join in Oracle by placing a plus sign (+) in parentheses following the column names from the optional table in your WHERE clause. 您可以通过在WHERE子句中的可选表中的列名称后的括号内加一个加号(+)来指定Oracle中的外部联接。 For example: 例如:

 SELECT ut.table_name, uc.constraint_name FROM user_tables ut, user_constraints uc WHERE ut.table_name = uc.table_name(+); 

The (+) after uc.table_name makes the user_constraint table optional. uc.table_name之后的(+)使user_constraint表为可选。 The query returns all tables, and where there are no corresponding constraint records, Oracle supplies a null in the constraint name column. 该查询返回所有表,并且在没有对应的约束记录的地方,Oracle在约束名称列中提供一个空值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM