how many types of joins are there in mysql or sql [closed]

强颜欢笑 提交于 2019-12-09 07:53:35

问题


I've heard there are 3 types of joins

I'm not sure of the exact names. Googling has turned up a variety of terms like :

Cross join , left join , right join , inner join , outer join, self join....

Could anyone tell me how many joins exist in MySQL all in all.


回答1:


The joins are

1. Inner Join or Equi join
2. Self Join
2. Outer Join
   outer join is again classified into
   a) Left Outer Join
   b) Right Outer Join
   c) Full Outer Join
3. Cross join



回答2:


Please see SQL JOIN:

The JOIN keyword is used in an SQL statement to query data from two or more tables, based on a relationship between certain columns in these tables.

Tables in a database are often related to each other with keys.

A primary key is a column (or a combination of columns) with a unique value for each row. Each primary key value must be unique within the table. The purpose is to bind data together, across tables, without repeating all of the data in every table.

Different SQL JOINs

  1. JOIN: Return rows when there is at least one match in both tables
  2. LEFT JOIN: Return all rows from the left table, even if there are no matches in the right table
  3. RIGHT JOIN: Return all rows from the right table, even if there are no matches in the left table
  4. FULL JOIN: Return rows when there is a match in one of the tables

http://w3schools.com/sql/sql_join.asp




回答3:


MySql 13.2.9.2. JOIN Syntax

join_table:
    table_reference [INNER | CROSS] JOIN table_factor [join_condition]
  | table_reference STRAIGHT_JOIN table_factor
  | table_reference STRAIGHT_JOIN table_factor ON conditional_expr
  | table_reference {LEFT|RIGHT} [OUTER] JOIN table_reference join_condition
  | table_reference NATURAL [{LEFT|RIGHT} [OUTER]] JOIN table_factor

SQL Server FROM (Transact-SQL)

<joined_table> ::= 
{
    <table_source> <join_type> <table_source> ON <search_condition> 
    | <table_source> CROSS JOIN <table_source> 
    | left_table_source { CROSS | OUTER } APPLY right_table_source 
    | [ ( ] <joined_table> [ ) ] 
}
<join_type> ::= 
    [ { INNER | { { LEFT | RIGHT | FULL } [ OUTER ] } } [ <join_hint> ] ]
    JOIN


来源:https://stackoverflow.com/questions/15377552/how-many-types-of-joins-are-there-in-mysql-or-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!