a表                                    b表    
 数据库的四种连接方式
    





		
据库的四种连接方式           数据库的四种连接方式
    





		
据库的四种连接方式

a.id同parent_id   存在关系

----------------------------------------------------------------------------------------------------------   
 1)内连接:相当于select a.*,b.* from a,b where a.id = b.id
  select   a.*,b.*   from   a   inner   join   b     on   a.id=b.parent_id       
  结果是     
数据库的四种连接方式
    





		
据库的四种连接方式

----------------------------------------------------------------------------------------------------------  
2)左连接:左表的挨个信息去查询,查不到则将右边控制为null进行显示
  select   a.*,b.*   from   a   left   join   b     on   a.id=b.parent_id       
  结果是     
数据库的四种连接方式
    





		
据库的四种连接方式

----------------------------------------------------------------------------------------------------------  
3) 右连接:右表的挨个信息去查询,查不到则将左边控制为null进行显示
  select   a.*,b.*   from   a   right   join   b     on   a.id=b.parent_id       
  结果是     
数据库的四种连接方式
    





		
据库的四种连接方式

----------------------------------------------------------------------------------------------------------  
 4) 完全连接: MySQL暂不支持完全连接

----------------------------------------------------------------------------------------------------------  

 

 

 


区分:

select * from  a left   join   b     on   条件1 

select * from  a left   join   b     on   条件1  where 条件2             相当于再次过滤 

 a表                                    b表    
 数据库的四种连接方式
    





		
据库的四种连接方式           数据库的四种连接方式
    





		
据库的四种连接方式

a.id同parent_id   存在关系

----------------------------------------------------------------------------------------------------------   
 1)内连接:相当于select a.*,b.* from a,b where a.id = b.id
  select   a.*,b.*   from   a   inner   join   b     on   a.id=b.parent_id       
  结果是     
数据库的四种连接方式
    





		
据库的四种连接方式

----------------------------------------------------------------------------------------------------------  
2)左连接:左表的挨个信息去查询,查不到则将右边控制为null进行显示
  select   a.*,b.*   from   a   left   join   b     on   a.id=b.parent_id       
  结果是     
数据库的四种连接方式
    





		
据库的四种连接方式

----------------------------------------------------------------------------------------------------------  
3) 右连接:右表的挨个信息去查询,查不到则将左边控制为null进行显示
  select   a.*,b.*   from   a   right   join   b     on   a.id=b.parent_id       
  结果是     
数据库的四种连接方式
    





		
据库的四种连接方式

----------------------------------------------------------------------------------------------------------  
 4) 完全连接: MySQL暂不支持完全连接

----------------------------------------------------------------------------------------------------------  

 

 

 


区分:

select * from  a left   join   b     on   条件1 

select * from  a left   join   b     on   条件1  where 条件2             相当于再次过滤 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-10
  • 2021-06-07
  • 2022-12-23
  • 2022-12-23
  • 2021-08-30
  • 2021-07-12
猜你喜欢
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2021-09-17
  • 2022-12-23
  • 2021-11-23
相关资源
相似解决方案