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 401087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:00:07+00:00 2026-05-12T17:00:07+00:00

Let say that I have 2 tables with the same structure : STOCK and

  • 0

Let say that I have 2 tables with the same structure : STOCK and NEW_STOCK.
These tables have a primary key composed of (ID_DATE, ID_SELLER, ID_INVOICE, ID_DOC).

Now, I need to get for every (ID_DATE, ID_SELLER, ID_INVOICE, ID_DOC), the value of the amount (field AMOUNT) regarding this requirement:

If a record is present in NEW_STOCK, I get the AMOUNT from NEW_STOCK, otherwise, I get the AMOUNT from STOCK table.

Note that ID_DATE and ID_SELLER are the inputs given to the query, i.e. a query that considers only STOCK table will look like :

select AMOUNT, ID_DATE, ID_SELLER, ID_INVOICE
    from STOCK
    where ID_DATE = 1
      and ID_SELLER = 'SELL1';

STOCK :

+---------+-----------+------------+--------+--------+
| ID_DATE | ID_SELLER | ID_INVOICE | ID_DOC | AMOUNT |
+---------+-----------+------------+--------+--------+
|       1 |     SELL1 |        IN1 |   DOC1 |    100 |
|       1 |     SELL1 |        IN2 |   DOC2 |     50 |
|       1 |     SELL1 |        IN3 |   DOC3 |     42 |
+---------+-----------+------------+--------+--------+

NEW_STOCK:

+---------+-----------+------------+--------+--------+
| ID_DATE | ID_SELLER | ID_INVOICE | ID_DOC | AMOUNT |
+---------+-----------+------------+--------+--------+
|       1 |     SELL1 |        IN2 |   DOC2 |     12 |
+---------+-----------+------------+--------+--------+

Then, I must get the following results:

+---------+-----------+------------+--------+--------+
| ID_DATE | ID_SELLER | ID_INVOICE | ID_DOC | AMOUNT |
+---------+-----------+------------+--------+--------+
|       1 |     SELL1 |        IN1 |   DOC1 |    100 |
|       1 |     SELL2 |        IN2 |   DOC2 |     12 |
|       1 |     SELL3 |        IN3 |   DOC3 |     42 |
+---------+-----------+------------+--------+--------+

ps: I’m working on Oracle 10.

  • 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-12T17:00:07+00:00Added an answer on May 12, 2026 at 5:00 pm

    Use outer join and NVL(arg1, arg2) function.
    It returns first argument if it is not NULL, otherwise it returns second argument. Example:

    select s.AMOUNT, s.ID_DATE, s.ID_SELLER, s.ID_INVOICE,
       NVL(n.AMOUNT, s.AMOUNT) amount       
    from STOCK s, NEW_STOCK n
    where s.ID_DATE = n.ID_DATE(+) 
      and s.ID_SELLER = n.ID_SELLER(+)
      and s.ID_INVOICE = n.ID_INVOICE(+)
      and s.ID_DOC = n.ID_DOC(+)
      and s.ID_DATE = 1
      and s.ID_SELLER = 'SELL1';
    

    You can use LEFT OUTER JOIN syntax instead of (+) if you find it more readable. I’m using Oracle since v7 and I like (+) more.

    Here is LEFT OUTER JOIN syntax:

    select s.AMOUNT, s.ID_DATE, s.ID_SELLER, s.ID_INVOICE,
       NVL(n.AMOUNT, s.AMOUNT) amount       
    from  STOCK s left outer join NEW_STOCK n 
          on s.ID_DATE = n.ID_DATE
             and s.ID_SELLER = n.ID_SELLER
             and s.ID_INVOICE = n.ID_INVOICE
             and s.ID_DOC = n.ID_DOC
    where s.ID_DATE = 1
      and s.ID_SELLER = 'SELL1';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have two tables that look like this: TH TH TH TH
I have a function that updates several tables. As an example, let's say it
Let's say I have two tables of similar structure, but one is empty and
Let's say I have these tables/models: Product - id - last_updated_date - name -
Let's say I have 3 tables (significant columns only) Category (catId key , parentCatId)
let's say that I have a table called Items (ID int, Done int, Total
I have this table: id feed_id ... Let's say that I have 500 rows
Let's say I have a table that has user_id, date, score, and every user
Let's say I have a MySQL table that is something like this: software table:
Let's say I have 3 MySQL table. A song db called songs that has

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.