Duplicate of https://www.sqlservercentral.com/Forums/1907056/Union-ALl
Like I posted in your other topic today, please don't make a duplicate topic. If you post a question and you don't get the answer and instead get questions about your data, set up, etc, answer those questions. Asking the question in a new topic is going to make the chances of you getting the answer to your question lower.
Also, try to make your Topics have relevant subjects. You've posted a lot of questions with simply the subject "Query" or . If you use a proper subject then people will be more interested in taking the time and effort into answering you; if you can't take the time to write a proper question and even make a relevant subject, why should they take the time to answer your question? it also helps others in the future should they have the same question as you.
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does :-P
Please always remember to encapsulate your code in IFCode Markup. For example [code=sql] [/code]
to read Jeffs Guide on how to post SQL questions, and get swift and helpful answers from the community