I have three queries:
SELECT EVENT_TITLE, ORIG_START_DT FROM EVENT_MAIN WHERE USERID='4' AND EVENT_STATUS='P'
SELECT GREET_TITLE, BROADCAST_SCH_DT FROM GREET_MAIN WHERE USERID='4' AND GREET_STATUS='P'
SELECT POLL_TITLE,CREATE_DTTM FROM POLL_MAIN WHERE USERID='4' AND POLL_STATUS='P'
How can I combine these three queries into single one to get result like this.
Tables may contain more than one row for each USERID for same status.
EVENT_TITLE | ORIG_START_DT | GREET_TITLE | BROADCAST_SCH_DT | POLL_TITLE | CREATE_DTTM
Use
UNION(implicit distinct) orUNION ALLlike so:Update
If you want to get the data from these three queries in the form:
You can do this:
SQL Fiddle Demo
This will give you something like:
Note that: As far as I know, this query, this way, will cross join the three tables, since I didn’t specify a
JOINcondition, becuase you didn’t determine in your question. If there is any relation between the three tables, specify aJOINcondtion using theONclause.