--- join query the database multi-table query

 

Join syntax (that is connected to several tables into a virtual table, easy access)

 

Cross-connect

Indeed, cross-connection is connected to the two tables do not set any condition results.

Cross-connection is also commonly called a "Cartesian product" - may be more mathematically.

 

from  表1   join  表2 

More invalid data is not recommended

  En:

Table 1 from the Join Table 1. Table 2 ON = Table 2. Field 1 Field 2;

Find (filtered) value field in Table 11 is the results of the cross-connect table is equal to those of Table 2 Field 2 of row values.

The most widely used,

A plurality of tables connected

SELECT * FROM Table. 1 JOIN Table 2 ON = Table 2. Table 1 Field Field
 JOIN Table 2. Table 3 ON = Table 3 Field Field

 

Left [outer] connection

from Table 1 left [outer] join in Table 2 on the connection conditions.

In the left side of the main table table, empty columns are automatically filled with null

Right [outer] Connection:

from Table 1 right [outer] join in Table 2 on the connection conditions.

In the table on the right side of the main table, empty columns are automatically filled with null

Subqueries to find a common point connected in series

 In can be connected to a plurality of values

where in the operand (value 1, value 2, ....)

Indicates that the operand (field value) is equal to the subqueries only either one, even if the condition

Joint inquiry

Keyword union query is: union

Union query is to query the results of two select statements of "stacked" together to become a "great result."

Query results can be two "joint" of pre-conditions are: the result is equal to the number of fields. Column is equal

1 select statement

union 

select statement 2;

1, the output section of two select statements (result fields) the same number, the same type of application typically makes sense.

2, the result set of a select field is subject to the first sentence of the field.

3, a first field select statement can do the alias, the alias if done, subsequent where, group, order, etc. should be used the alias clause.

4, if you want to sort or limit the entire joint results, you should select for their statements in parentheses:

(Select statement 1)

union

(Select statement 2)

order  by .....  limit ....;

 

Guess you like

Origin www.cnblogs.com/layuechuquwan/p/11220563.html
Recommended