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

  • Home
  • SEARCH
  • 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 9021399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:14:49+00:00 2026-06-16T05:14:49+00:00

In Oracle, is it possible to perform a union where the duplicate condition is

  • 0

In Oracle, is it possible to perform a union where the duplicate condition is on a single column rather than the entire row?

I have table Aand B that have 2 columns: item_name, price. I’d like to create a view that for certain item_names, it looks in table A to see if the item_name is present, and if so use the price in A, if not go to B and use the price in B, then union the rest of item_name in B that have not yet been added to the view.

For example,

 Table A                Table B
 ----------------       ----------------
 item_name price        item_name price
 ----------------       ----------------
 shoe      10           shoe      8
 socks     2            socks     4
 shirt     5            t-shirt   3
 gloves    1            glasses   15
                        pants     7

For shoe and socks I’d like to use table A‘s prices if available, and if not use table B. So in the end, my view should look like this:

 View
 -----------------------
 item_name price source
 -----------------------       
 shoe      10    A
 socks     2     A
 t-shirt   3     B
 glasses   15    B
 pants     7     B

I tried

 select * from A a
 where item_name in ('shoe', 'socks')
 union
 select * from B b
 where b.item_name not in 
     (select item_name from A
      where item_name in ('shoe', 'socks'))

Which I don’t like because the query select * from A where item_name in ('shoe', 'socks') is duplicated. Is there a better/more efficient way of doing this?

  • 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-06-16T05:14:50+00:00Added an answer on June 16, 2026 at 5:14 am

    I think you are looking for a join:

    select coalesce(a.item_name, b.item_name) as item_name,
           coalesce(a.price, b.price) as price,
           (case when a.price is not null then 'A' else 'B' end) as source
    from a full outer join
         b
         on a.item_name = b.item_name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Convert Unixtime to Datetime SQL (Oracle) We have a table of type
Possible Duplicate: Rename Oracle Table or View I know you can use ALTER TABLE
Possible Duplicate: Printing Table's structure/schema oracle has 'DESCRIBE' to get all the details of
Possible Duplicate: Oracle SQL - How to Retrieve highest 5 values of a column
Possible Duplicate: Oracle SQL - How to Retrieve highest 5 values of a column
Possible Duplicate: oracle insert if row not exists I am using the query below
Possible Duplicate: Oracle SQL - How to Retrieve highest 5 values of a column
Possible Duplicate: Oracle RAC and sequences I have a Oracle RAC configured in my
Possible Duplicate: Why does Oracle 9i treat an empty string as NULL? I have
Possible Duplicate: Oracle table change monitor This is the question that is asked to

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.