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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:07:35+00:00 2026-05-30T10:07:35+00:00

No real way for me to succinctly summarize this one. I have two database

  • 0

No real way for me to succinctly summarize this one. I have two database tables (PostgreSQL 9.x)

The first one contains Products, for example. Each product has a name and a unique ID.

The second table contains sales records and has the name of each product sold but not the ID. I want to update this table with the ‘product_id’ of the corresponding unique entry in the Products table. However, sometimes, product names show up in the Sales table that do not exist in the Products table. When I find one of these, I want to add a product record to the Products table and then update the sales record(s) for that product name with the new product_id foreign key.

I have some SQL that does the first part: updates the sales record with the product_id that corresponds with the unique name in the Products table. I just need to know how to first sweep the sales table for unknown product names and create them in the Products table.

  • 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-30T10:07:36+00:00Added an answer on May 30, 2026 at 10:07 am

    Something like this:

    -- add any products not in products table
    INSERT INTO Products(ProductName)
    SELECT DISTINCT S.ProductName
    FROM Sales AS S
    WHERE NOT EXISTS(
        SELECT * 
        FROM Products AS P
        WHERE P.ProductName = S.ProductName
    );
    
    -- now just do update 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code (which is way simplified from the real code): public interface
In ASP.NET, is there any way to get the real raw URL? For example,
REAL newbie here to Objective C and Cocoa. I have this 'if statement' if
Now this may be something I imagined, or something real either way I am
I manage the real 404 errors in this way: application = webapp.WSGIApplication([ ('/', MainPage),
I know about code-behind files, but what is the best real-world way of Designers
The real question: Is there a way to clear certain attributes for all components
Is there a more efficient way to clamp real numbers than using if statements
Is there an easy way to find out the current (real or cpu) run
Real UID, effective UID, and some systems even have a saved UID. What's the

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.