a b 两表 没有任何关系 现在需要联合两表,select后的结果集得到这样的显示效果 结果集有ID,TYPE,DATE这3个字段 ID就是A 或B表原有数据的ID值,type只为0或者1 0就是来自A表的数据 1就是来自B表的数据。结果集需要根据时间的降序排列。A 表数据类似
ID Title content date
1 aaa aaa 2008-9-5
2 bbb bbb 2008-9-6B 表数据类似
ID title content date
1 cccc cccc 2008-9-4
2 ddd dddd 2008-9-5
3 eee eee 2008-9-7那么最后select的结果如下
ID Type date
3 1 2008-9-7
2 0 2008-9-6
2 1 2008-9-5
1 0 2008-9-5
1 1 2008-9-4
ID Title content date
1 aaa aaa 2008-9-5
2 bbb bbb 2008-9-6B 表数据类似
ID title content date
1 cccc cccc 2008-9-4
2 ddd dddd 2008-9-5
3 eee eee 2008-9-7那么最后select的结果如下
ID Type date
3 1 2008-9-7
2 0 2008-9-6
2 1 2008-9-5
1 0 2008-9-5
1 1 2008-9-4
1.增加一个区分每个表的类型字段值.
2.合并a,b两个表.
3.用SQL查询得出结果.可以用以下SQL语句实现:Select ID,Type,Date from (
Select ID,Title,Content,Date,0 as Type from a
union all
Select ID,Title,Content,Date,1 as Type from b
) as result
order by Date desc