-1

I am working on a student management project on pdo php mysql. I need to insert multiple rows like student payable amount available to specific group of students. Or send a billing to a group of student. How do i insert this into sql database? Is insert multiple rows a possible solution?

Edit

My reference will be base from other table.. it goes like this.

table 1 -

-------------------------
| id | name     | group |
-------------------------
| 10 | John     | A     |
| 11 | James    | A     |
| 12 | Julius   | B     |
-------------------------

table 2

-------------------------
| id | stud_id | amount |
-------------------------
| 1 | 10       | 500.00 |
| 2 | 11       | 500.00 |
-------------------------

notice julius was not included since he has different group.

Pradeep Sanjaya
  • 1,816
  • 1
  • 15
  • 23
John Arzaga
  • 103
  • 1
  • 1
  • 11
  • 1
    post your code and error you are getting if you have tried, or google for tutorials . – Prafulla Kumar Sahu Nov 23 '15 at 05:19
  • 1
    [`INSERT INTO table2 SELECT * FROM table1 WHERE GROUP = 'A'` - INSERT ... SELECT Syntax](http://dev.mysql.com/doc/refman/5.7/en/insert-select.html) – Sean Nov 23 '15 at 05:42
  • one collects points in Answers @sean :) ... trigger finger waiting ... 78 more points ya know – Drew Nov 23 '15 at 05:43
  • @drew only if OPs actually select answers. Don't feel like wasting time giving complete answers when OPs don't respond to question/answers – Sean Nov 23 '15 at 05:45
  • plus he has a dangling one from a while back. The one where he said "Thanks! Kooilnc... have a great day." – Drew Nov 23 '15 at 05:45
  • @ParthChavda I disagree that this question is a duplicate of that one. VALUES() cannot be used here, as far as I am aware. – Strawberry Nov 23 '15 at 07:53

1 Answers1

-1

INSERT statements that use VALUES syntax can insert multiple rows.

INSERT INTO table2 (stud_id,amount)
SELECT id,'500.00' FROM table1 WHERE group = 'A' 
Abhishek Sharma
  • 6,689
  • 1
  • 14
  • 20