Hi Yes you are right , union is a best bet for this. For union your number of total columns and their data type should be same:- Firstly you need to decide the column headers which you would get from following query:- For example activityid, activityname, starttime, endtime, body, recipient Secondly try to put column of same dataype and similar value under one column value and if you dont have relevant column put a null value (so that union can be done) like this :- select activityid, activityname, starttime, endtime, body, recipient (if you dont have any header put the hardcoded value) from some_tables union select activityid, 'Meeting',starttime, null, null, receipient from some_tables2 union select activityid, 'Meeting',null, endtime, body121, null from some_tables2 The key here is to build individual queries for all different activities by adding nulls or calculated columns so that each resultset has equal number of columns....then at the very end apply a union operator. Hope this helps.
@erlokeshsharma08 covered most of what you need. (+1) for his answer. I just want to add a few points I believe are important when working with UNION. 1. Set the data types of the columns in the first SELECT to be the highest precision and scale you need for that column. For example, if you have integers, 7-digit numbers with 4-digit decimals, and 10-digit numbers with 3-digit decimals, you will want to ensure the data type is decimal(14,4) to cover the max of every scenario (up to 10 digits to the left of the decimal and up to 4 digits to the right). I often use CONVERT for each column to explicitly ensure the data types are set appropriately. 2. UNION ALL will perform faster than UNION because it doesn't have to perform the extra step of removing duplicates. If you know you won't have duplicate rows, use UNION ALL.