insert multiple rows using subquery insert multiple rows using subquery sql sql

insert multiple rows using subquery


INSERT INTO qualification_lookup (variation, correct_qualification) select Qualification,'A-Level' from student   where Qualification like 'A%' 


    INSERT INTO qualification_lookup (variation, correct_qualification) select Qualification, 'A-Level' from student where Qualification like 'A%'

Is the correct syntax


You need to think through how you build your query - consider what you would get if you just ran this:

 SELECT (select Qualification from student where Qualification like 'A%') ,'A-Level'

the exact error you are getting would be my guess - you have a list of many Qualifications trying to be matched with a single string - 'A-level'.

On the other hand, this will work fine

 select Qualification, 'A-Level' from student where Qualification like 'A%'

The trick with INSERT and UPDATE statements, to my mind is to write a SELECT statement that gets you what you need and then wrap that up like

INSERT INTO qualification_lookup (variation, correct_qualification) select Qualification, 'A-Level' from student where Qualification like 'A%'