mysql select join on_MySQL SELECT语法(三)JOIN语法详解

SELECTselect_exprFrom table_references JOIN...WHERE...

如上所示,MySQL支持在table_references后添加JOIN选项作为SELECT语句的一部分,当然也可以在多表的DELETE和UPDATE。

下面列出了JOIN的详细语法:

table_references:

escaped_table_reference [, escaped_table_reference] ...

escaped_table_reference:

table_reference

| { OJ table_reference }

table_reference:

table_factor

| joined_table

table_factor:

tbl_name [PARTITION (partition_names)]

[[AS] alias] [index_hint_list]

| table_subquery [AS] alias

| ( table_references )

joined_table:

table_reference [INNER | CROSS] JOIN table_factor [join_specification]

| table_reference STRAIGHT_JOIN table_factor

| table_reference STRAIGHT_JOIN table_factorONsearch_condition

| table_reference {LEFT|RIGHT} [OUTER] JOIN table_reference join_specification

| table_reference NATURAL [{LEFT|RIGHT} [OUTER]] JOIN table_factor

join_specification:ONsearch_condition

|USING(join_column_list)

join_column_list:

column_name [, column_name] ...

index_hint_list:

index_hint [, index_hint] ...

index_hint:

USE {INDEX|KEY}

[FOR {JOIN|ORDER BY|GROUP BY}] ([index_list])

| {IGNORE|FORCE} {INDEX|KEY}

[FOR {JOIN|ORDER BY|GROUP BY}] (index_list)

index_list:

index_name [, index_name] ...

一、表引用(table reference)

一个表引用也被称为一个JOIN表达式。表引用(当它引用分区表时)可能有PARTITION选项,包括一个由逗号分隔的分区,子分区或两者皆有的列表。此选项紧跟在的名字之后,并在任何别名声明之前。此选项的作用是仅从列出的分区或子分区中选择数据行,而且将忽略列表中未命名的任何分区或子分区。see Section 22.5, “Partition Selection”。

table_factor语法是MySQL对标准SQL中的扩展。标准SQL只接受table_reference,而不是一对括号内的列表。

如果table_reference项列表中的每个逗号被视为内连接(INNER JOIN),则这是保守的扩展。例如:

SELECT * FROM t1 LEFT JOIN(t2, t3, t4)ON (t2.a = t1.a AND t3.b = t1.b AND t4.c = t1.c)

等价于:

SELECT * FROM t1 LEFT JOIN (t2 CROSS JOIN t3 CROSS JOINt4)ON (t2.a = t1.a AND t3.b = t1.b AND t4.c = t1.c)

在MySQL中,JOIN,CROSS JOIN,和INNER JOIN 在语义上是等价的࿰

你可能感兴趣的:(mysql,select,join,on)