欢迎访问YiiCms企业站系统 English/中文
联系电话:13240702278
<p><span class="rich_media_meta meta_original_tag" style="margin: 0px 8px 10px 0px; padding: 1px 0.5em; display: inline-block; vertical-align: middle; font-size: 15px; border: 1px solid rgb(158, 158, 158); color: rgb(140, 140, 140); border-radius: 20% 50%; line-height: 1.1; max-width: none;">原创</span> <span class="rich_media_meta rich_media_meta_text" style="margin: 0px 8px 10px 0px; padding: 0px; display: inline-block; vertical-align: middle; font-size: 16px; color: rgb(140, 140, 140); max-width: none;">2015-11-17</span> <span class="rich_media_meta rich_media_meta_text" style="margin: 0px 8px 10px 0px; padding: 0px; display: inline-block; vertical-align: middle; font-size: 16px; color: rgb(140, 140, 140); max-width: none;">58沈剑</span> <a class="rich_media_meta rich_media_meta_link rich_media_meta_nickname" href="http://mp.weixin.qq.com/s?__biz=MjM5ODYxMDA5OQ==&mid=400889133&idx=1&sn=3ea1c06fc76e92349a822f41f45b77b5&scene=21##" style="margin: 0px 8px 10px 0px; padding: 0px; color: rgb(96, 127, 166); text-decoration-line: none; display: none; vertical-align: middle; font-size: 16px; max-width: none;">架构师之路</a></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; word-wrap: break-word !important;">废话不多说,直接上图秒懂。<br/></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; word-wrap: break-word !important;"><strong style="margin: 0px; padding: 0px; max-width: 100%; box-sizing: border-box !important; word-wrap: break-word !important;">t1</strong>表的结构与数据如下:</p><p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; word-wrap: break-word !important;"><img class="" src="http://mmbiz.qpic.cn/mmbiz/YrezxckhYOyxnN0uV6foI2UFk0R6eGh9sYCr5qzeVribHEicibtmcia7Z2iaVHtePtH0S7ib1DLDfMX6KlicDpeZt41ng/640?tp=webp&wxfrom=5&wx_lazy=1"/></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; word-wrap: break-word !important;"><strong style="margin: 0px; padding: 0px; max-width: 100%; box-sizing: border-box !important; word-wrap: break-word !important;">t2</strong>表的结构与数据如下:</p><p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; word-wrap: break-word !important;"><img class="" src="http://mmbiz.qpic.cn/mmbiz/YrezxckhYOyxnN0uV6foI2UFk0R6eGh9iacWt47uE0Qa8RGwFMczMowMRojrxPaYb4URMvibhhMCPUqdpibw9UYrg/640?tp=webp&wxfrom=5&wx_lazy=1"/></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; word-wrap: break-word !important;"><br/></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; word-wrap: break-word !important;"><strong style="margin: 0px; padding: 0px; max-width: 100%; box-sizing: border-box !important; word-wrap: break-word !important;">inner join</strong></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; word-wrap: break-word !important;">select * from t1 <span style="margin: 0px; padding: 0px; max-width: 100%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(255, 0, 0);">inner join</span> t2 on t1.id = t2.id;</p><p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; word-wrap: break-word !important;"><img class="" src="http://mmbiz.qpic.cn/mmbiz/YrezxckhYOyxnN0uV6foI2UFk0R6eGh9gDUXqia4JBNYyDibsZ05gibTG2UT4WbWuuxRV89OiaBLD7siavohADDvtdg/640?tp=webp&wxfrom=5&wx_lazy=1"/></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; word-wrap: break-word !important;">inner join会把<span style="margin: 0px; padding: 0px; max-width: 100%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(255, 0, 0);">公共部分的数据查询出来</span>:</p><p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; word-wrap: break-word !important;"><img class="" src="http://mmbiz.qpic.cn/mmbiz/YrezxckhYOyxnN0uV6foI2UFk0R6eGh9oqD0OHrW7huRNpnFkiazn0gnM8IR3WV7gnI42OGpdHatzRic4z7HeexQ/640?tp=webp&wxfrom=5&wx_lazy=1"/></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; word-wrap: break-word !important;"><br/></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; word-wrap: break-word !important;"><strong style="margin: 0px; padding: 0px; max-width: 100%; box-sizing: border-box !important; word-wrap: break-word !important;">left join</strong></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; word-wrap: break-word !important;">select * from t1 <span style="margin: 0px; padding: 0px; max-width: 100%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(255, 0, 0);">left join</span> t2 on t1.id = t2.id;</p><p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; word-wrap: break-word !important;"><br/></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; word-wrap: break-word !important;">left join查询出来的<span style="margin: 0px; padding: 0px; max-width: 100%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(255, 0, 0);">结果和前表记录数一样多</span>,<span style="margin: 0px; padding: 0px; max-width: 100%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(255, 0, 0);">后表如果没有对应记录,则列为空</span>:</p><p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; word-wrap: break-word !important;"><br/></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; word-wrap: break-word !important;"><br/></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; word-wrap: break-word !important;"><strong style="margin: 0px; padding: 0px; max-width: 100%; box-sizing: border-box !important; word-wrap: break-word !important;">right join</strong></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; word-wrap: break-word !important;">right join能转化为left join,例如:</p><p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; word-wrap: break-word !important;">select * from <strong style="margin: 0px; padding: 0px; max-width: 100%; box-sizing: border-box !important; word-wrap: break-word !important;">t1</strong> <span style="margin: 0px; padding: 0px; max-width: 100%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(255, 0, 0);">right join</span> t2 on t1.id = t2.id;</p><p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; word-wrap: break-word !important;">能转化为<br/></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; word-wrap: break-word !important;">select * from <strong style="margin: 0px; padding: 0px; max-width: 100%; box-sizing: border-box !important; word-wrap: break-word !important;">t2</strong> <span style="margin: 0px; padding: 0px; max-width: 100%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(255, 0, 0);">left join</span> t1 on t1.id = t2.id;<br/></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; word-wrap: break-word !important;">只是前表发生了变化而已。</p><p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; word-wrap: break-word !important;"><br/></p><p style="margin-top: 0px; margin-bottom: 0px; padding: 0px; max-width: 100%; clear: both; min-height: 1em; box-sizing: border-box !important; word-wrap: break-word !important;">大伙可结合自己的业务场景,选择正确的join。</p><p><br/></p>
上一条 http code, http header 下一条 test

联系我们

公司: 在北京网络科技有限公司

联系人: 李先生

QQ: 739800600 点击这里给我发消息

E-mail: 739800600@qq.com

地址: 北京市丰台区大红门

QQ群:248898849

超值活动: 香港空间+域名+程序(YiiCms)+维护=1000元/年

捐赠我们

支付宝扫码捐赠我们

小电影