This query will return a list of project IDs that represent forum threads:
SELECT id FROM `proj_objects` WHERE type='fthread';
This query will subscribe a user (whose ID in the users table is '37') to the forum thread with an ID of '122':
INSERT INTO `subscrips` VALUES ( 37, 122 ) ;
I'd like to insert multiple rows that will subscribe user 37 to all project objects where type is fthread. Can I do this in a single query?
Multiple-row subqueries are nested queries that can return more than one row of results to the parent query. Multiple-row subqueries are used most commonly in WHERE and HAVING clauses. Since it returns multiple rows, it must be handled by set comparison operators (IN, ALL, ANY).
INSERT-SELECT-UNION query to insert multiple records Thus, we can use INSERT-SELECT-UNION query to insert data into multiple rows of the table. The SQL UNION query helps to select all the data that has been enclosed by the SELECT query through the INSERT statement.
Answer: D. Multiple-row subqueries return more than one row of results. Operators that can be used with multiple-row subqueries include IN, ALL, ANY, and EXISTS.
MySQL INSERT multiple rows statement In this syntax: First, specify the name of table that you want to insert after the INSERT INTO keywords. Second, specify a comma-separated column list inside parentheses after the table name. Third, specify a comma-separated list of row data in the VALUES clause.
Use:
INSERT INTO `subscrips`
SELECT 37, id
FROM `proj_objects`
WHERE type = 'fthread'
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