首頁 >後端開發 >php教程 >求mysql 2个表一行查询语句

求mysql 2个表一行查询语句

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB原創
2016-06-13 12:02:18944瀏覽

求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 記錄要刪除?
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn