急!!!高分请教MySQL查询问题
现有表A和B
A表有一列bid允许为空,对应B表主键自增列
如果建视图的话,视图只会显示bid不为空的数据
A表bid为空的数据则显示不出
现在我想既有对应关系,又能显示A表bid为空的数据
只用一条语句,有办法实现么?该怎么写
- SQL code
<!---ecms Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->例如:表A-----------------id bid name1 2 abc2 def3 1 ghi表B-----------------bid other1 aaa2 bbb如果A的bid关联了B的bid结果则为:-----<p>5本文来源gao!daima.com搞$代!码#网#</p><pre>搞代gaodaima码
————id bid name other1 2 abc aaa3 1 ghi bbb以上A表bid为空的列就没有了现在我想要的结果则是:—————–id bid name other1 2 abc aaa2 def3 1 ghi bbb
高分请教
——解决方案——————–
去搜一下join left和join right我相信能够解决你的问题
——解决方案——————–
select a.id,a.bid,a.name, b.other from A a left join B b on a.bid=b.bid;