i saw this
In MySQL, joins work for INSERT, UPDATE, and DELETE statements. It's possible to change data in more than one table when joining tables in an UPDATE or DELETE statement.
in an answer for a question from the mysql certification guide. is it true? inserts with joins? an example of it?
The INSERT command is used to add new data into a table. MySql will add a new row, once the command is executed. The date and string values should be enclosed in single quotes. The numeric values do not need to be enclosed in quotes.
To insert data into a MySQL table, you would need to use the SQL INSERT INTO command. You can insert data into the MySQL table by using the mysql> prompt or by using any script like PHP.
First, you must specify the name of the table. After that, in parenthesis, you must specify the column name of the table, and columns must be separated by a comma. The values that you want to insert must be inside the parenthesis, and it must be followed by the VALUES clause.
There are two basic syntax of INSERT INTO statement is as follows: INSERT INTO TABLE_NAME (column1, column2, column3,... columnN)] VALUES (value1, value2, value3,... valueN);
You can INSERT ... SELECT with mysql, which is probably what they mean. For example:
INSERT INTO tableNew (col1, col2)
SELECT tbl1.col1, tbl2.col2
FROM tbl1 JOIN tbl2
To complete the set, here's one for DELETE. This is a common method for deleting rows together with their dependencies without triggers.
DELETE users, comments
FROM users JOIN comments ON comments.author=users.id
WHERE users.isspammer=1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With