insert multiple rows using subquery
INSERT INTO qualification_lookup (variation, correct_qualification)
select Qualification,'A-Level' from student where Qualification like 'A%'
Insert Into with subquery to insert multiple rows into database
Something like this should work:
scmd.CommandText = "INSERT INTO notificationAck (Email,
Notification,
isAcknowledged)
SELECT Email, '" + notification + "', 0
FROM AspNetUsers";
INSERT INTO SELECT
does not require VALUES
. Hence, you only have to use a SELECT
statement that retrieves Email
field from AspNetUsers
plus two constant values.
How do I insert multiple rows with a subquery as one of the value?
Use INSERT ... SELECT ...
without VALUES
:
INSERT INTO accounts_account_preferences (account_id, preference_id)
SELECT account_id, 2
FROM accounts_account_preferences
WHERE preference_id = 1
MySQL How do you INSERT INTO a table with a SELECT subquery returning multiple rows?
INSERT INTO Results (People, names )
SELECT d.id, 'Henry'
FROM Names f
JOIN People d ON d.id = f.id
Combine the static string Henry
with your SELECT
query.
inserting multiple row in sql using subquery
Assuming your test table is already created and contains only a loan_id
, all you have to do is drop values
and remove the now redundant parentheses.
INSERT INTO test SELECT loan_id FROM loan_transaction_mcg
MSQL Insert multiple row from select statment with subquery and 1 value
Your first query is missing a comma and repeats VALUES
. I also recommend listing the columns
INSERT INTO PERMISSION (role_id, permission_id)
VALUES ('2', '2'),
('4', '2');
Note that ids are usually numbers. If that is the case, then remove the single quotes.
For the second query, use INSERT . . . SELECT
"
INSERT INTO permission (role_id, permission_id)
select rp.role_id, 2
from role_permission rp
group by rp.role_id
having sum(rp.permission_id = 2) = 0;
Related Topics
SQL Server Management Studio - How to Change a Field Type Without Dropping Table
Multiple Tables Need One to Many Relationship
SQL Unpivot Multiple Columns Data
Search by Many Optional Parameters in Spring Data JPA Repository
How to Add 10 Seconds in Current_Timestamp SQL ( Oracle )
Postgresql Does Not Use a Partial Index
Postgresql Function Definition in Squirrel: Unterminated Dollar-Quoted String
SQL Constraint: Date a Is Before Date B -- How
Searching a Column Containing CSV Data in a MySQL Table for Existence of Input Values
Using 'In' with a Sub-Query in SQL Statements
Calling Stored Procedure While Passing Parameters from Access Module in Vba