sql inner join, outer join, cross join

1. Inner join

1.1. Equi-join: Use the equal sign (=) operator in the join condition to compare the column values ​​of the joined columns, and the query result lists all the columns in the joined table, including the duplicate columns.

1.2. Unequal value join: Use other comparison operators other than the equal operator in the join condition to compare the column values ​​of the joined columns. These operators include >, >=, <=, <, !>, !<, and <>.

1.3. Natural join: The equal (=) operator is used in the join condition to compare the column values ​​of the joined columns, but it uses the select list to indicate the columns included in the query result set, and deletes duplicate columns in the join table.

Inner join: The inner join query operation lists the rows of data that match the join condition, and it uses comparison operators to compare the column values ​​of the joined columns.

    select*from book ,stu  where book.sutid = stu.stuid;  

2. Outer join

2.1. Left join: Based on the left table, connect the data of book.stuid = stu.stuid, and then display the corresponding items that are not in the left table, and the column in the right table is NULL

    select * from book as a left join stu as b on a.sutid = b.stuid
2.2. Right join: Based on the right table, connect the data of book.stuid = stu.stuid, then display the corresponding items that are not in the right table, and the column in the left table is NULL
    select * from book as a right join stu as b on a.sutid = b.stuid
2.3. Full join: A full outer join returns all rows in the left and right tables. When a row has no matching rows in another table, the select list column of the other table contains null values. If there are matching rows between the tables, the entire result set row contains the data values ​​of the base table
    select*from book as a fullouterjoin stu as b on a.sutid = b.stuid    

3. Cross-connect

Cross Join: A cross join returns all rows from the left table, each row from the left table combined with all the rows from the right table. Cross joins are also known as Cartesian products.

select * from book as a cross join stu as b order by a.id

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324742295&siteId=291194637