0

我想知道是什么

根据主页上显示的时间戳从三个不同的表和 ORDER 中获取不同项目详细信息的最佳方法

Suppose :
Table 1
+.......+..........+..........+.......+.........+..........+.........+...........+
:postId : sourceId : fee      : pay   : company : elig     : howto   : timestamp :
+.......+..........+..........+.......+.........+..........+.........+...........+

Table 2
+.......+..........+..........+.......+.........+..........+.........+...........+
:postId : sourceId : skill    : title : funct   : location : exper   : timestamp :
+.......+..........+..........+.......+.........+..........+.........+...........+

Table3
+.......+..........+..........+.......+.........+..........+.........+...........+
:postId : sourceId : company  : title : sector  : quali    : state   : timestamp :
+.......+..........+..........+.......+.........+..........+.........+...........+

所有表格在项目之间没有相似之处,我不能将它们全部放在一张表格中。

现在,我想在我的应用程序上显示所有表中的项目HOME PAGE according to their timestamp

我知道如何按顺序获取。我正在使用以下方式:

 SELECT * FROM Table1;   //Dispaly all items of table1
and then 
 SELECT * FROM Table2;   //Dispaly all items of table2

Similarlly from table3.

有没有办法从所有三个表中选择所有并按它们的时间戳排序。

我读了一篇文章,它告诉使用一个单独的表, (id, timestamp, table_type)并根据时间戳按 id 顺序获取项目,但在我的情况下,所有表项目都有不同的顺序(可能是来自不同表的两个项目具有相同的 id)。

4

1 回答 1

1

这个怎么样:

select timestamp, postId, sourceId, fee, pay, company, elig, howto, 
       null as skill, null as title, null as funct, null as location, null as exper, 
       null as company, null as title, null as sector, null as quali, null as state
from   table1
union all
select timestamp, postId, sourceId, null as fee, null as pay, null as company, null as elig, null as howto, 
       skill, title, funct,  location, exper, 
       null as company, null as title, null as sector, null as quali, null as state
from   table2
union all
select timestamp, postId, sourceId, null as fee, null as pay, null as company, null as elig, null as howto, 
       null as skill, null as title, null as funct, null as location, null as exper, 
       company, title, sector, quali, state
from   table3
order by timestamp;
于 2013-06-15T05:14:03.920 回答