【Access】SQL语句中左(外)连接的运用
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="http://mmbiz.qpic.cn/mmbiz/rlzBtFD4J7bHPL5whO9ForibWyuBWeicIwK0FrK76kvhbTtHpOSAXK2WEFeDUGB05S3sI1Chcbf8rPzZ4iaUf1R6A/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">大众</span>好,上次课程<span style="color: black;">咱们</span>讲了内连接的<span style="color: black;">运用</span>,本节课再跟随<span style="color: black;">博主</span>来学习一下左(外)连接。<span style="color: black;">咱们</span><span style="color: black;">晓得</span>等值链接、自然链接、内连接在运行的时候,某些属性值<span style="color: black;">区别</span>会<span style="color: black;">引起</span>这些元组会被舍弃,<span style="color: black;">那样</span><span style="color: black;">怎样</span><span style="color: black;">保留</span>这些被丢失的信息呢,此时外连接就<span style="color: black;">处理</span>了相应的问题。本节课<span style="color: black;">咱们</span>先来学习下左(外)连接,<span style="color: black;">这儿</span>先放上左(外)连接的SQL语法格式:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">SELECT ……FROM 表1 LEFT JOIN 表2 ON 表1.某字段 = 表2.某字段</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">左(外)连接中的“左”是要把左表要舍弃的元组<span style="color: black;">保存</span>在结果集中,右表对应的列填NULL。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">来看个例子,<span style="color: black;">此刻</span>假设<span style="color: black;">咱们</span>的Access数据库中有<span style="color: black;">这般</span>两张表,表一:有a、b、c三个字段;表二有c、d、e三个字段。如下图是两个表:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">表一:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="http://mmbiz.qpic.cn/mmbiz_png/rlzBtFD4J7a43iaIlkZwt6DuzggE0TDB0o6ExItD3icP7wCqMibcYTMPyNlpNM9lGfI962kPRh4SpCVChEQhHcA3A/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">表二:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="http://mmbiz.qpic.cn/mmbiz_png/rlzBtFD4J7a43iaIlkZwt6DuzggE0TDB0AhiaQBLKFkzic4KDDzkQ4b6ULZduMOwMiaDoQtmiazN6yCCsmAlYteLibvg/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">左(外)连接<span style="color: black;">不可</span>在Access<span style="color: black;">查找</span>设计器里面直接操作,<span style="color: black;">必要</span>在SQL设计视图里直接写SQL语句,下面<span style="color: black;">咱们</span>做一个左(外)连接,书写如下的SQL语句:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="http://mmbiz.qpic.cn/mmbiz_png/rlzBtFD4J7a43iaIlkZwt6DuzggE0TDB0Q07ccyLrXDHoWsd1V4t3icqZPc74DdcPtFgpk8ibOdV6gYZlpEwYwSibw/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">咱们</span><span style="color: black;">能够</span>看到用SQL语句中<span style="color: black;">运用</span>的是LEFT JOIN子句,<span style="color: black;">而后</span>用ON连接两个表的字段,这<span style="color: black;">便是</span>左(外)连接,下图是这个左(外)连接的结果:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="http://mmbiz.qpic.cn/mmbiz_png/rlzBtFD4J7a43iaIlkZwt6DuzggE0TDB0EVibUxXWuSXeofJTsRsdDwXYfnI8Uhlrtkl4sonibFrG8MEyj7GysXqQ/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">咱们</span><span style="color: black;">能够</span>看到左(外)连接不仅<span style="color: black;">选取</span>属性值相等的<span style="color: black;">哪些</span>元组,其他在左表(表一)不相等的元组被<span style="color: black;">保存</span>下来了,在右表(表二)不相等的元组被舍弃掉了。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">我刚才说左(外)连接<span style="color: black;">不可</span>直接在Access<span style="color: black;">查找</span>设计器里面直接操作,此时<span style="color: black;">咱们</span><span style="color: black;">能够</span>返回到Access<span style="color: black;">查找</span>设计器里<span style="color: black;">瞧瞧</span>是什么样的:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="http://mmbiz.qpic.cn/mmbiz_png/rlzBtFD4J7a43iaIlkZwt6DuzggE0TDB0ger5eaE5DZGQ6PWWV7QcBaia5XsAx7WRiaN2EicO5CIBYyftZpTjkGib8g/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">这下你该明白了,<span style="color: black;">咱们</span>看到红色框里是一个连接箭头,在Access<span style="color: black;">查找</span>设计器里<span style="color: black;">咱们</span><span style="color: black;">不可</span>单纯地<span style="color: black;">经过</span>简单的拖动鼠标等做出这个效果,故<span style="color: black;">必须</span>直接在SQL设计视图里写SQL语句。</p><span style="color: black;">亦</span>许你<span style="color: black;">此刻</span>还看不出左(外)连接有什么<span style="color: black;">实质</span><span style="color: black;">道理</span>,<span style="color: black;">由于</span>你还<span style="color: black;">无</span>碰到<span style="color: black;">必须</span>的时候,<span style="color: black;">期盼</span><span style="color: black;">大众</span>记住这个左(外)连接,日后相信<span style="color: black;">必定</span>会用到!
快捷查看<span style="color: black;"><strong style="color: blue;"><span style="color: black;">平台回复数字“6”查看Access常规知识目录</span></strong></span><img src="http://mmbiz.qpic.cn/mmbiz/rlzBtFD4J7bkbMpYp6z2iaQOUgLR7wtBN0V589WntqDjjkPRQyOMv0D5oRerLhfpne4lHz1ibGVmKialGTT1XgADA/0?wx_fmt=gif&tp=webp&wxfrom=5&wx_lazy=1" style="width: 50%; margin-bottom: 20px;"><img src="http://mmbiz.qpic.cn/mmbiz/rlzBtFD4J7bkbMpYp6z2iaQOUgLR7wtBN24jrungXmsO2p7APFD1YfUia1pnGx0xicjiavA6T6rT1qAeVsf1OIo7nA/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">职场办公,快人一步!</p><span style="color: black;">你有两种方式约这个<span style="color: black;">博主</span>:</span><strong style="color: blue;"><span style="color: black;">Q Q:</span></strong>2456917009<strong style="color: blue;"><span style="color: black;"><span style="color: black;">微X</span>:</span></strong>HC10000086
我完全赞同你的观点,思考很有深度。 你的话语如春风拂面,温暖了我的心房,真的很感谢。
页:
[1]