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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:37:41+00:00 2026-06-01T22:37:41+00:00

I have table1 with columns ( id, id_user ) and table2 with columns (id,

  • 0

I have table1 with columns ( id, id_user ) and table2 with columns (id, username).
The users are registered in table2. So what I want is to insert the table2.id of the new registered users in table1.id_user.

I have this query:

INSERT INTO table1 (id_user) SELECT id FROM table2;

but the result is:

for example I have in table1.id:

 id
 1
 2
 3

and when the new users register in table2 the table1.id looks like this:

id
1
2
3
1
2
3
4

and it repeats all the data every time there is a new registered user.
How can I fix this to only add the newly registered user?

  • 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-01T22:37:42+00:00Added an answer on June 1, 2026 at 10:37 pm
    INSERT INTO table1  (id_user) 
        SELECT id FROM table2 where id not in (select id_user from table1)
    

    If you use a DB trigger then you could insert the new user id from table2 in table1 automatically.

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

Sidebar

Related Questions

I have table1 with columns: def_id, def_name, username etc I have another table table2
This should be straightforward. I have three tables (relevant columns shown). users : ID,USERNAME,PWD
I have 3 tables with the following columns : * users : user_id *
i have a table with columns ID,SUBJECT,BRANCH i have select the rows which satisfies
Let's say I have a table Foo . This table has the columns ID
Is it possible in MySQL to insert a row into table2 automatically when a
I have below query running on my users and chats table to join and
I have two tables table1 = records, table2 = duplicates. Both tables contain a
I don't understand how to get the columns I want from rails. I have
Say I have a table like this: create table users ( user_id int not

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.