Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I like to insert total doctors in a department by getting a value from doctor table.

What I have tried:

Insert into Department (Total_Doctor)
values (( Select Count(*) from department Dep, Doctor do
Where Dep.De_ID = Do.De_ID
Group by Dep.Name
));
Error:
Sub query returned more than 1 value.
This is not premitted when the subquery follows =, != ,< <=, >, >= or when the subquery is used as an expression
Posted
Updated 26-Jul-18 19:46pm

1 solution

Your inner query:
Select Count(*) from department Dep, Doctor do
Where Dep.De_ID = Do.De_ID
Group by Dep.Name
Returns more than one row, because it is a GROUP BY query and that is what it is supposed to do!

But the outer query expects only one value, so you get an error.
Look at using INSERT INTO SELECT Statement[^] instead.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900