UNION Query Columns
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 6 of 6

Thread: UNION Query Columns

  1. #1
    Join Date
    Feb 2009
    Posts
    3

    UNION Query Columns

    Hi All,
    I have a union query, please see below:

    select to_char(some_date,'MON') JAN
    from dual
    where to_char(some_date,'MON') = &MONTH
    UNION
    select to_char(some_date,'MON') FEB
    from dual
    where to_char(some_date,'MON') = &MONTH
    UNION
    select to_char(some_date,'MON') MAR
    from dual
    where to_char(some_date,'MON') = &MONTH

    Based on the WHERE Clause, the query runs perfectly! Our requirement is to change the column name as well. If the month is JAN should also display JAN, If FEB, then a column name should be FEB, instead no matter what query executes it always display the JAN (First column)

    Is there any way to get this?
    Thanks in advance.

  2. #2
    Join Date
    Jul 2002
    Location
    Lake Worth, FL
    Posts
    1,470

    Talking First select rules!

    A union ALLWAYS takes the column names from the FIRST select!
    "The person who says it cannot be done should not interrupt the person doing it." --Chinese Proverb

  3. #3
    Join Date
    Dec 2000
    Posts
    126

    Exclamation sample data

    Hi,

    Please post your sample data

  4. #4
    Join Date
    Feb 2009
    Posts
    3
    Hi,
    The query is self-described. If you run you will know my requirement.
    Thanks.

  5. #5
    Join Date
    Mar 2007
    Location
    Ft. Lauderdale, FL
    Posts
    3,554
    Quote Originally Posted by ap63 View Post
    The query is self-described. If you run you will know my requirement.
    You are correct AND you already got your answer.
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.

  6. #6
    Join Date
    Nov 2000
    Location
    Baltimore, MD USA
    Posts
    1,339
    Quote Originally Posted by ap63 View Post
    Hi,
    The query is self-described. If you run you will know my requirement.
    Thanks.
    You are asking for help and when we ask you for clarification, you are unwilling to do so???

    What are you smoking?

    Your query tells us what you have now. Obviously that does NOT satisfy the requirements or you wouldn't have a question to ask. So since it does NOT satisfy the requirements, how can we possibly glean the requirements FROM it??

    My assumption is that what you are asking for is a rotated resultset, but unless you make the effort to at least meet us halfway, we will never know. Remember that it is *you* who came to *us* asking for help.
    Christopher R. Long
    ChrisRLong@HotMail.Com
    But that's just my opinion. I could be wrong

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width