0

I have a select statement which fetches 100 rows of data and inserts it in a table. However, I want to insert to insert 1 into the other column for all the rows I have inserted in the neighbouring column.

This is my insert select statement

insert into examination_data (ed_cs_id,ed_examination_id) 
VALUES (( 
          select cs_id 
          from class_students 
          where cs_class_id = 1 AND cs_year_id = 1 ),1);

On running the query, I get this error

/* SQL Error (1242): Subquery returns more than 1 row */

icodebuster
  • 8,890
  • 7
  • 62
  • 65
  • 1
    You can find answer to your quesiton here: http://stackoverflow.com/questions/5391344/insert-with-select – Wirus Jul 22 '13 at 06:42
  • First,when u try to insert into a table, remove the key word 'VALUES', Secondly, the number of columns which u want to insert does not match to the number of columns in your query. – Krishna Rani Sahoo Jul 22 '13 at 07:19

2 Answers2

0
insert into examination_data (ed_cs_id,ed_examination_id)  
          select cs_id,1 
          from class_students 
where cs_class_id = 1 AND cs_year_id = 1;

fiddle

Praveen Prasannan
  • 7,093
  • 10
  • 50
  • 70
0

Try this

insert into examination_data (ed_cs_id,ed_examination_id)  (select cs_id,1 as "COLUMN_NAME" from class_students where cs_class_id = 1 AND cs_year_id = 1);
Ravi
  • 30,829
  • 42
  • 119
  • 173