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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:48:20+00:00 2026-05-16T06:48:20+00:00

I have two tables, ‘user’ and ‘account’ with a 1:1 relationship. account has a

  • 0

I have two tables, ‘user’ and ‘account’ with a 1:1 relationship.

account has a fk user_id, and account has unique account_id

I have to take a csv upload with up to 50k rows and for each row either:

  • insert the data as a new row (in to account and user) if account.account_number is unique
  • update the account table row if the account.account_number already exists
  • remove the account and user row if the account.account_number doesnt exist in the csv.

So far I’m dealing with the account table, as this has the account.account_number col to check for unique, but adding a new row to this table relies on having the user_id from a new row already added to the user table.

INSERT INTO account (account_number, trans_rate....etc) VALUES (multiple data sets),(...),(....) ON DUPLICATE KEY UPDATE ...etc

So that deals with the account table, doing updates / inserts as required. But of course, the user_id column is left NULL as the user records haven’t been created.

I’m wondering if I can embed the insert statement for a new user row within the above statement, but I don’t know where to start… And a bit of googling hasnt led me to beleive its actually possible thus far.

Or any other ideas?..

I can see how to do this with several queries per row, but I’m concerned about the time the data import is going to take if I do it with so many seperate queries.

  • 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-16T06:48:20+00:00Added an answer on May 16, 2026 at 6:48 am

    Upload the data into a ‘staging table’ – and then perform two upserts into first the user table, and second the account table – the query used for the second of these would be the staging table joined to the user table on e.g. user name or SSN (whatever the candidate key for users is).

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

Sidebar

Related Questions

I have two tables user table user_id | name | 1 | peter |
I have two tables, a user table and a application table: User id username
I have two tables connected with one to many relationship. Parent Table is a
I have two tables inside a database. One stores unique userNames and a unique
I have two tables: Transactions and TransactionAgents. TransactionAgents has a foreign key to Transactions
I have two tables, orders and old_orders. Each table has some similar fields and
I have two tables that are all the same, except one has a timestamp
I have two tables such as DTTable1 and DTTable2. It has the following records.
I have two tables imagesgroup and images imagesgroup has following fields id and group_name
I have two tables: USER: userID | uName | ----------------- 1 | John 2

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.