MySql database to learn - Description of multi-table join query self-understanding

One: Preface

These days in the learning database part because lectures in schools is more confused, after learning feel now thinking more clearly, for multi-table joins query with a new understanding.

Two: the assumption

Suppose there are two tables: A, B.

III: the connection between the two tables

Connection is divided into two tables, inner, outer, cross-three.

Query inner join is divided into two kinds of implicit and explicit.

Outer join query is divided into left and right two kinds.

Cross is a record two tables do product, largely because of the resulting records are not directly linked, so cross-connect basic query does not make sense.

Four: En

Keywords within the connection: inner join ... (inner may be omitted)

Implicit within the connector: select (fields to be queried) from A a, B b where a.A_id = b.B_id;

Explicit inner connecting: select (fields to be queried) from A join B on (note that this must not be used on where) A_id = B_id;

Summary: inner join query query is the intersection between the two tables.

Five: outer join

Keywords outer connection: outer join ..... on (outer may be omitted)

Left outer: select (fields to be queried) from A left join B on (...);

Right outer join: select (fields to be queried) from A right join B on (...);

Summary: left outer join query is the intersection of the left part of the table (the statement as A) and two full tables. Corresponding to the right and the left outer nature outer connector connecting the same.

Six: cross-connect

Statement: select * from A, B; (if there are three records in Table A, B has two records, consistent with the results of the query Cartesian product, there are 6 records)

 

Guess you like

Origin www.cnblogs.com/zhang188660586/p/11209372.html