sql联接两个表 [英] sql join two table

查看:74
本文介绍了sql联接两个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TABLE A >>
uid name
1   test1
2   test2
3   test3
4   test4

TABLE B >>
uid address
1   address1
2   address2
4   address3

RESULT
1   test1   address1
2   test2   address2
3   test3
4   test4   address3

任何人都可以向我展示如何编写查询并如上所述获取结果,非常感谢! 我试过加入,左右加入.全部都没有结果.

Can anyone show me how to write a query and fetch the result as above, Thanks very much! i have tried join, left and right join. all result nothing.

推荐答案

您可以在这两个表之间编写左外部联接.最好的理解方法是检查下面的图像

You can write left outer join between this two tables Best way to understand is check the below image

查询您的要求

SELECT A.uid, A.name, B.address FROM A LEFT JOIN B ON A.uid=B.uid 

阅读有关代码项目的原始文章将对您有很大帮助:

Reading this original article on The Code Project will help you a lot: Visual Representation of SQL Joins.

在以下位置找到原始版本:

Find original one at: Difference between JOIN and OUTER JOIN in MySQL.

这篇关于sql联接两个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆