This is the query:
INSERT INTO qualification_lookup (variation, correct_qualification)
SELECT (SELECT Qualification FROM student WHERE Qualification like 'A%') ,'A-Level'
This is the error I get if I try to execute the query.
Msg 512, Level 16, State 1, Line 1 Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. The statement has been terminated.
I am new to SQL so kindly if someone tells me any alternative to do that.
INSERT INTO qualification_lookup (variation, correct_qualification)
select Qualification,'A-Level' from student where Qualification like 'A%'
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%'
INSERT INTO qualification_lookup (variation, correct_qualification)
select Qualification, 'A-Level' from student where Qualification like 'A%'
Is the correct syntax
The problem is this subquery:
select Qualification from student where Qualification like 'A%'
returns several rows. That's why you get error message 512
No need to use that.
This would be enough:
INSERT INTO qualification_lookup (variation, correct_qualification)
select Qualification, 'A-Level' as correct_qualification
from student where Qualification like 'A%'
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