j8typz 发表于 2024-8-4 11:10:20

软考之数据库内连接左连接右连接


    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">有如下两张<span style="color: black;">相关</span>表</strong></p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-axegupay5k/efc0bd37c8cc4ed3b61dab367b2d8200~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723340396&amp;x-signature=YAuw2%2FZ1pexChIGVkmT4SeGSK%2BI%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">mysql数据库<span style="color: black;">插进</span>两张表</strong></p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/47c143b32b7e4fd5b729c252162b28f4~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723340396&amp;x-signature=jZw9NOiGu7vAU1hAIkTldqjH8MM%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/0f3b3adc211142e0ab0cfa184ba480a1~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723340396&amp;x-signature=rOeRGR6zbL4yT5QC7aV0zMqnnmU%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">内连接——<span style="color: black;">表示</span>两个表中有联系的所有数据</strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">方式一:select * from unicom.staff inner join unicom.profession where unicom.staff.profession = </p>unicom.profession.professi
    on;
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">方式二: select * from unicom.staff, unicom.profession where unicom.staff.profession = </p>unicom.profession.profession;

    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/4313d44339354c87a05f4e1990cc0951~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723340396&amp;x-signature=99kk3SkgXqewWOTKEPFFIUEx%2FTM%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">左连接——以左表为参照,<span style="color: black;">表示</span>所有数据,右表中<span style="color: black;">无</span>则以null<span style="color: black;">表示</span></strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">select * from unicom.staff left join unicom.profession on unicom.staff.profession = unicom.profession.profession;</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/d73f8d5c151a4d06acf29059d03ba41e~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723340396&amp;x-signature=sqx6FDRMymqC2z%2BzXK62BnTF1Bo%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">右连接——以右表为参照<span style="color: black;">表示</span>数据,,左表中没有则以null<span style="color: black;">表示</span></strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">select * from unicom.staff right join unicom.profession on unicom.staff.profession = unicom.profession.profession</span>;</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p26-sign.toutiaoimg.com/tos-cn-i-6w9my0ksvp/7beab1134a584ad19884e02242ae76da~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1723340396&amp;x-signature=opBagjYJ29bPfPP0JgtmrqdnB9I%3D" style="width: 50%; margin-bottom: 20px;"></div>




qzmjef 发表于 2024-10-18 04:20:30

感谢楼主分享,祝愿外链论坛越办越好!

nykek5i 发表于 2024-11-11 06:39:34

回顾历史,我们感慨万千;放眼未来,我们信心百倍。
页: [1]
查看完整版本: 软考之数据库内连接左连接右连接