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?
If you use a DB trigger then you could insert the new user id from table2 in table1 automatically.