[SQL] multi-table outer join in a query, on, where

Prior to the conclusion simple and crude , coupled multi-table queries, ON earlier than where functions, the system according to the coupling condition between the first respective table, the tables after the synthesis a plurality of temporary table, and then filtered by a match where, where the the statement is true, then can check out, but by external connection, such as connection left on, regardless of whether it is true, will the contents of the table are left out of the inquiry.

The basic syntax for multi-table query

select*from table_1,table_2 where table_1.no=table_2.no

Example:

select*from stu,sc where stu.sno=sc.sno

 

 

 Detected stu table and the table sc sno equal record

(Left) outer connection: record table will be 全部表示out of the table 只会显示符合搜索条件的记录, while the right table in 没有记录place with both NULLalternatives

select*from table_1 left outer join table_2 on table_1.no=table_2.no

NOTE: outer can be omitted, and the full right connecting external connection need only be modified to right or left Full, consistent grammar

Example:

select*from stu left outer join sc on stu.sno=sc.sno

 

Contrast where, found 20 records, found more than 11 records, because no matter sno match, and whether the end of the statement is true, the display left a priority list of all the records , and does not match the right table are set to NULL

 

Guess you like

Origin www.cnblogs.com/ByTwo/p/12006446.html