-3

我正在使用 PHP。我有以下表格

1)Posts

||  post_id  |  post  |  date_posted  ||


2) Photo

||  photo_id  |  photo  |  date_posted||


3) Video

||  video_id  |  video  |  video_link  |  date_posted||

我想检索所有表中存在的所有行并按 date_posted 排序。

我想稍后在检索行后区分哪一行是视频,哪一行是帖子

我怎样才能做到这一点?

4

2 回答 2

1
 (
   SELECT video_id   AS id,
          'Post'     AS content_type,
          post       AS content,
          date_posted
     FROM Posts

        UNION ALL

   SELECT photo_id   AS id,
          'Photo'    AS content_type,
          photo      AS content,
          date_posted
     FROM Photo

           UNION ALL

   SELECT video_id   AS id,
          'Video'    AS content_type,
          video      AS content,
          date_posted
     FROM Video
 )
 ORDER BY date_posted DESC
于 2013-07-27T00:03:03.867 回答
0
SELECT post_id as id, post as data, date_posted FROM Posts
UNION ALL
SELECT photo_id, photo, date_posted FROM Photo
UNION ALL
SELECT video_id, video, date_posted FROM Video
ORDER BY date_posted DESC

也许?..

于 2013-07-26T23:59:41.753 回答