Home >Backend Development >PHP Tutorial >求mysql 2个表一行查询语句

求mysql 2个表一行查询语句

WBOY
WBOYOriginal
2016-06-13 12:02:18937browse

求mysql 2个表一起查询语句.

本帖最后由 dxmbxh6 于 2014-06-13 14:14:55 编辑 A表 
id                 time                                        title
1              2014-05-01                 aaaaaaaaaaaa
2             2014-05-02                 bbbbbbbbbbbbb
3

B表
id                     time                                           url
1              2014-05-03               cccccccccccccccccccccc
2              2014-05-04                ddddddddddddddddddd
3              2014-05-05                eeeeeeeeeeeeeeeeeee
4              2014-05-06                fffffffffffffffffffffffffffffffffffffff

想要的结果

type             id              date                             title                                                              
a                  1              2014-05-01                 aaaaaaaaaaaa
b                  1              2014-05-03                cccccccccccccccccccccc
b                  2              2014-05-04                ddddddddddddddddddd
b                  3              2014-05-05                eeeeeeeeeeeeeeeeeee
------解决方案--------------------
这表设计的就有问题。没法实现
------解决方案--------------------
结果的type 字段在两个表里都没有,来自哪里?
------解决方案--------------------
<br />select 'a' as tname , id, time , title from a <br />union all <br />select 'b' as tname , id , time  ,url from b <br />order by 2,1<br />

------解决方案--------------------
沒看出什麼邏輯
為甚麼a表的id=2 與b表的id=4 記錄要刪除?
Statement:
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