MySql database query of the connection

Join query into several ways in MySql database:

1. inner join query

  En achieved by keyword query inner join keyword to achieve through the code:

SELECT  *  from Table. 1 Inner  the Join Table 2 ON Table 1. Field = Table 2. Field

  The principle is that the two data tables are linked by a specified field, and the display data out link;

It understood to be removed in the intersection of two tables.

2. Left query link

  Left connection is achieved by left join query keyword, code implementation:

SELECT  *  from Table. 1 left  the Join Table 2 ON Table 1. Field = Table 2. Field

  The principle is that the left table as the data base by specifying the field link, then look for the right data in the table, if there is the right table data is data shows that if the right data in the table does not exist, filled with NULL.

3. Right inquiry link

  Right connection is achieved by right join query keyword, code implementation:

SELECT  *  from Table. 1 right  the Join Table 2 ON Table 1. Field = Table 2. Field

  The principle is the basis for the right table as the data link by the specified field, then left to find the data in the table, if there is data left the table data is displayed, if data in the table does not exist then left filled with NULL.

Note: the left and right connections can be converted to each other, the positions of the two tables point to another can.

4. Self-inquiry link

  Since link query is a query link itself, can be achieved through inner join keyword, code implementation:

select * fromas a inner joinas b on a.id = b.id

  The principle of self-link that is to be modeled as a table around two tables, and then even table query.

It can be understood as an alias by the way since it considered two new tables, query data link by means of internal connections.

Which is mainly used on an entire area of ​​the table, such as: production of three linkage at selected areas

 

Guess you like

Origin www.cnblogs.com/chao666/p/12045694.html
Recommended