Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3984210
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:44:33+00:00 2026-05-20T05:44:33+00:00

I have a homework assignment in SQL for Oracle 10g where I have to

  • 0

I have a homework assignment in SQL for Oracle 10g where I have to apply union to two different select statements, to return two columns. I need the values of each cell under vendor_state to indicate CA and every other value in another state to return “Outside CA”, to indicate they’re elsewhere.

I applied the union and produced the two columns and the listings for CA, but many other state IDs were listed and I couldn’t find an explanation for how to change the actual values in the query itself. Eventually, I stumbled on an answer, but I can’t explain why this works. The code is as follows:

  SELECT vendor_name, 
         vendor_state
    FROM vendors 
   WHERE vendor_state IN 'CA'
UNION
  SELECT vendor_name, 
         'Outside CA' AS vendor_state
    FROM vendors
   WHERE vendor_state NOT IN 'CA'
ORDER BY vendor_name

This gives me the exact answer I need, but I don’t know why the aliasing in the second select statement can behave this way….no explanation is given in my textbook and nothing I’ve read indicates that column aliasing can be done like this. But, by switching the column name and the alias value, I have replaced the value being returned rather than the column name itself…I’m not complaining about the result, but it would help if I knew how I did it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:44:33+00:00Added an answer on May 20, 2026 at 5:44 am

    The trick is:

    In the 1st SELECT, “vendor_state” is the value of the field itself, from the table. And, because of the WHERE clause, you will only have ‘CA’

    In the 2nd SELECT, “vendor_state” is NOT the value from the database field. Rather, its merely an alias for the literal value ‘Outside CA’

    Because both names match (as required by the UNION), your end result “looks like” all values came from same place, when in fact they didnt.

    Maybe this will show better:

    SELECT vendor_name, vendor_state, vendor_state AS vendor_state_new
      FROM vendors 
     WHERE vendor_state IN 'CA'
     UNION
    SELECT vendor_name, vendor_state, 'Outside CA' AS vendor_state_new
      FROM vendors
     WHERE vendor_state NOT IN 'CA'
    ORDER BY vendor_name
    

    Now, for both queries, vendor_state show the database value. And calculated_state show the database value for the 1st SELECT, and the ‘Outside CA’ for the 2nd.

    In your query, vendor_state do the role of my vendor_state_new: show database value for 1st, calculated value for 2nd. And the AS is ommitted in 1st SELECT because vendor_state AS vendor_state would be redundant (but it can be done for clarification purposes, and its a nice habit to do so when you mix calculated and “raw” values in a given colum name)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a homework assignment where I need to take input from a file
I have a homework assignment to write a multi-threaded sudoku solver, which finds all
I have a homework assignment. I'm not looking for anyone to do the work
I have done a homework assignment, here is the problem statement: Your program should
A recent homework assignment I have received asks us to take expressions which could
For a homework assignment in linear algebra, I have solved the following equation using
I have three questions regarding a homework assignment for C++. The goal was to
As part of a homework assignment, I have to program a simple chess game
We've gotten a homework assignment in Java, which relates to inheritance. I don't have
I'm working on a homework assignment for CS1, and I almost have it finished

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.