使用UNION
(隐式不同)或UNION ALL
类似:
SELECT
EVENT_TITLE "Title",
ORIG_START_DT "DT"
FROM EVENT_MAIN WHERE USERID='4' AND EVENT_STATUS = 'P'
UNION ALL
SELECT
GREET_TITLE,
BROADCAST_SCH_DT
FROM GREET_MAIN WHERE USERID='4' AND GREET_STATUS = 'P'
UNION ALL
SELECT
POLL_TITLE,
CREATE_DTTM
FROM POLL_MAIN WHERE USERID='4' AND POLL_STATUS = 'P';
更新
如果要从表单中的这三个查询中获取数据:
EVENT_TITLE | ORIG_START_DT | GREET_TITLE | BROADCAST_SCH_DT | POLL_TITLE | CREATE_DTTM
你可以这样做:
SELECT
EVENT_TITLE ,
ORIG_START_DT ,
GREET_TITLE,
BROADCAST_SCH_DT,
POLL_TITLE,
CREATE_DTTM
FROM
(
SELECT *
FROM EVENT_MAIN
WHERE USERID='4' AND EVENT_STATUS = 'P'
) t1
INNER JOIN
(
SELECT *
FROM GREET_MAIN
WHERE USERID='4' AND GREET_STATUS = 'P'
) t2
INNER JOIN
(
SELECT *
FROM POLL_MAIN
WHERE USERID='4' AND POLL_STATUS = 'P'
) t3
这会给你类似的东西:
| EVENT_TITLE | ORIG_START_DT | GREET_TITLE | BROADCAST_SCH_DT | POLL_TITLE | CREATE_DTTM |
-------------------------------------------------------------------------------------------
| Title4 | O44 | DTdd | O44 | ddsfTdd | O44 |
| Title4 | O33 | DTdd | O44 | ddsfTdd | O44 |
........
请注意:据我所知,这种查询将交叉连接三个表,因为我没有指定JOIN
条件,因为您没有在问题中确定。如果三个表之间存在任何关系,请JOIN
使用该ON
子句指定条件。