0

私は何だろうと思っています

3 つの異なるテーブルから異なるアイテムの詳細を取得し、ホームページのタイムスタンプ表示に従って注文する最良の方法

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 :
+.......+..........+..........+.......+.........+..........+.........+...........+

すべての表に項目間の類似性はありません。すべてを 1 つの表にまとめることはできません。

今、アプリケーションのすべてのテーブルからアイテムを表示したいと思います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.

3 つのテーブルすべてからすべてを選択し、タイムスタンプで並べ替える方法はありますか。

別のテーブルを使用し、タイムスタンプによるID順に従ってアイテムをフェッチするように指示 する記事を読みました(id, timestamp, table_type)が、私の場合、すべてのテーブルアイテムの順序が異なります(異なるテーブルの2つのアイテムが同じ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 に答える