|
|
|
| Есть таблицы posts,events,articles. У них есть одинаковые столбцы id,title и есть столбцы владельца, дата-время создания и контента различающиеся по имени (creator_id и owner, datetime и created, content и text).
Как сделать результирующую общую таблицу со следующими полями:
id, createdate, creator, title, content
отсортировав по createdate в обратной последовательности? | |
|
|
|
|
|
|
|
для: yvgorshkov
(08.07.2013 в 11:42)
| | Получилось так:
SELECT `id`, `datetime` as `createdate`, `creator_id` as `creator`, `title`, `content` as `content` FROM {{articles}}
UNION SELECT `id`, `datetime` as `createdate`, `owner` as `creator`, `title`, `text` as `content` FROM {{events}}
UNION SELECT `id`, `created` as `createdate`, `creator_id` as `creator`, `title`, `content` as `content` FROM {{posts}}
ORDER BY `createdate` DESC
|
Но теперь нужен ещё один столбец type в котором будет указано из какой таблицы эта запись. | |
|
|
|
|
|
|
|
для: yvgorshkov
(08.07.2013 в 12:20)
| | Всё получилось:
SELECT `id`, `datetime` as `createdate`, `creator_id` as `creator`, `title`, `content` as `content`, \'article\' as `type` FROM {{articles}}
UNION SELECT `id`, `datetime` as `createdate`, `owner` as `creator`, `title`, `text` as `content`, \'event\' as `type` FROM {{events}}
UNION SELECT `id`, `created` as `createdate`, `creator_id` as `creator`, `title`, `content` as `content`, \'post\' as `type` FROM {{posts}}
ORDER BY `createdate` DESC
|
| |
|
|
|