I have 2 tables A and B with following records
--TABLE A--
id date value
1 09/01/2012 Reward
2 09/01/2012 Purchase
3 07/01/2012 Reward
4 07/01/2012 Purchase
--TABLE B--
id id_from_a date value
1 1 10/01/2012 Generated Rewrd
2 3 08/01/2012 Generated Reward
Now I want the result to be like below
id date value
1 10/01/2012 Generated Reward
1 09/01/2012 Reward
2 09/01/2012 Purchase
3 08/01/2012 Generated Reward
3 07/01/2012 Reward
4 07/01/2012 Purchase
I know using UNIONS will merge these 2 tables but how do i order it like i have mentioned above ?
A UNION can have a single ORDER BY clause specified at the end which applies to the entire, combined result set.
If you don’t need the deduplicating feature of the UNION operation, a UNION ALL will yield better performance.