>백엔드 개발 >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으로 문의하세요.