SQL INSERT statement for TWO TABLES at time with INNER JOIN

I have two tables helloand login_table, below, their structure

user_info
-------
some_id | name | address

login_table
-------
id | username | password

some_idand id- auto-increment indices.

Now how can I use the INSERTc operator INNER JOINinSQL

Currently I want to add the data below with the same some_idandid

`name` = John
`address` = wall street
`username` = john123
`password` = passw123

below code shows what i tried so far.

insert into login_table lt
INNER JOIN user_info ui ON ui.some_id = lt.id
(ui.name, ui.address, lt.username, lt.password) 
values
('John', 'wall street', 'john123', 'passw123')

And this is not one value, I want to add several values ​​at a time. How can i achieve.

thanks for the help.

+3
source share
2 answers

If you need to perform two operations INSERTatomically, use a transaction:

START TRANSACTION;
INSERT INTO login_table (username, password) VALUES ('john123', 'passw123');
INSERT INTO user_info (name, address) VALUES ('John', 'wall street');
COMMIT;

NB Your storage engine must support transactions for this (e.g. InnoDB).

, INSERT. :

INSERT, VALUES, . , . :

INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);

. , :

INSERT INTO tbl_name (a,b,c) VALUES(1,2,3,4,5,6,7,8,9);

VALUE VALUES . , , .

+10

. : :

insert into some_table(col1, col2) values (1,2), (3,4), (5,6);
0

All Articles