php+MySQL问题:有两个表,字段都一样,现在要把两个表里的信息查出来混合显示,要求按时间排序。

来源:百度知道 编辑:UC知道 时间:2024/06/03 10:05:12
该如何做呢?希望高手帮忙!
终于找到一个好方法:用联合查询,代码如下:
select id,title,`time`,'gg' as `type` from gonggao union select id,title,`time`,'tz' as `type` from tongzhi order by `time` desc limit 20;

查询结果得到两个数组,用array_merge()函数合并数组,然后sort应当就可以呢,只是一点粗浅的想法,不知道对不对。

写sql语句时加上表名就行了,如表为a,b则
select a.id,b.id from a,b
试一下