I'm trying to insert additional rows into a table which requires a value to be retrieved from another table. Below is an example query:
insert into a.grades (rollno, grade)
values(select rollno from b.students where ssn=12345, 'A');
Structure of b.students
table is rollno, ssn, name
.
I knew the above query is wrong. Is there a way to retrieve 1 value from other table while inserting a row?
Some DBMS would accept the following, with an extra set of parenthesis around the SELECT statement:
Columns in insert into and select must be equal