sql四种连接方式

it2022-05-05  57

1.内连接(inner  join) 只有两个表相匹配的行才能在结果集中显示出来 2.左连接(left  join) 以左表为主,左表所有的数据都会在结果集中出现,右表根据左表对应的数据显示,与左表匹配的数据会显示,没有匹配的地方会显示为空 3.右连接(right  join) 以右表为主,右表所有的数据都会在结果集中出现,左表根据左表对应的数据显示,与左表匹配的数据会显示,没有匹配的地方会显示为空 4完全连接(full  join) 完整外部联接返回左表和右表中的所有行。当某行在另一个表中没有匹配行时,则另一个表的选择列表列包含空值。如果表之间有匹配行,则整个结果集行 包含基表的数据值。   例子:   -------------------------------------------------   a表     id   name           b表     id   job   parent_id                 1   张3                      1     23     1                 2   李四                     2     34     2                 3   王武                     3     34     4         a.id同parent_id   存在关系   --------------------------------------------------    1.内连接:select a.*,b.* from a inner join b on a.id=b.parent_id 结果是       1   张3                      1     23     1      2   李四                     2     34     2    2.左连接:select a.*,b.* from a left join b on a.id=b.parent_id   结果是       1   张3                   1     23     1     2   李四                  2     34     2     3   王武                  null       3.右连接:select a.*,b.* from a right join b on a.id=b.parent_id   结果是         1   张3                   1     23     1      2   李四                  2     34     2      null                         3     34     4     4.完全连接:select a.*,b.* from a full join b on a.id=b.parent_id 结果是    1   张3         1     23     1     2   李四       2     34     2     null             3     34     4   3   王武        null     

转载于:https://www.cnblogs.com/yuer20180726/p/10905895.html

相关资源:Android通过webservice连接Sqlserver实例

最新回复(0)