Columns of second query appears in diff order when use UNION.

  • Hi All,

    --- Results of first query

    ServerAppNameVersion

    Srvr1App16.1.1016

    Srvr1App26.1.1033

    Srvr1App35.7.216

    --- Results of second query

    ServerAppNameVersion

    Srvr2App412.5

    --- Results when I UNION the above 2 queries.

    ServerAppNameVersion

    Srvr1App16.1.1016

    Srvr1App26.1.1033

    Srvr1App35.7.216

    12.5Srvr2App4

    Why the last row columns (second query results) comes is diff order

    Thanks in Advance.

  • Hi,

    Could you post that query?

    __________________________
    Allzu viel ist ungesund...

  • Thanks for your quick reply.

    Problem resolved. First query is Grouped By "AppName"

    and second query is Grouped By "Server".

    When I made first query to be grouped by "Server, AppName' result is coming properly.

    but, I am still not clear why should it make difference based on the group by columns. I dont understand.

    Thanks.

  • I'd really like to see the query you were running also... from what you've said, this shouldn't be happening. The proof is in the code. I'd be very appreciative if you would post it please.

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

  • Hi,

    Thanks for your response.

    I am sorry that I can't post the query here.

    I tried to simulate the issue in test, but couldn't.

    But beleive me, it's a strange problem. And one more thing...

    When I simply quey using "UNION" this issue occurs.

    But when I add "top 10 *" with same query, it just works fine.

    Anyways, when I am free, will try to put those records in some dummy tables and simulate the same error so that I can show you the error.

    Thanks again.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply