Home > Backend Development > PHP Tutorial > 急高分请问MySQL查询有关问题

急高分请问MySQL查询有关问题

WBOY
Release: 2016-06-13 10:16:11
Original
835 people have browsed it

急!!!高分请教MySQL查询问题
现有表A和B
A表有一列bid允许为空,对应B表主键自增列
如果建视图的话,视图只会显示bid不为空的数据
A表bid为空的数据则显示不出
现在我想既有对应关系,又能显示A表bid为空的数据
只用一条语句,有办法实现么?该怎么写

SQL code
<!--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结果则为:-----------------id    bid    name   other1     2      abc     aaa3     1      ghi     bbb以上A表bid为空的列就没有了现在我想要的结果则是:-----------------id    bid    name   other1     2      abc     aaa2            def3     1      ghi     bbb
Copy after login


高分请教

------解决方案--------------------
去搜一下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;
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template