以前总用where,但面对遗留系统里有很多这种sql的时候,要理解它做什么,就不得不去看join了

aid,aname,bid
----------------
1,one,1
3,three,3

bid,bname
---------------
1,b1
2,b2

join类型:
1.join,inner join
inner join=join=where.....
e.g:select * from [a] inner join [b] on a.bid=b.bid
result:
aid aname bid bname
-----------------------
1,one,1,b1

2.outer join
outer join分为left outer join 和right outer join和full outer join
e.g:select * from [a] left outer join [b] on a.bid=b.bid
result:
1,one,1,b1
3,three,3,null
e.g:select * from [a] left outer join [b] on a.bid=b.bid
result:
1,one,1,b1
null,null,null,b2

full outer join=left outer join+right outer join
outer可以去掉,直接left/right join

相关文章:

  • 2021-12-23
  • 2022-12-23
  • 2021-07-08
  • 2021-06-26
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-07
  • 2021-10-25
  • 2022-12-23
  • 2022-03-07
相关资源
相似解决方案