-3

I am working on PHP Codeigniter with MySQL database, I have two tables Student (Original table) and Student1 (temporary table) and both tables have different columns.

I am uploading bulk of student list from a CSV file into that Student1 (temporary table), later I have to move those student details into Student (Original table). How can I do this?

This is different case, I am not only asking about executing the query, instead I have to do it using MVC (CodeIgniter).

halfer
  • 19,824
  • 17
  • 99
  • 186
Kishan
  • 13
  • 6
  • 1
    Possible duplicate of [mysql :: insert into table, data from another table?](http://stackoverflow.com/questions/4241621/mysql-insert-into-table-data-from-another-table) – Hmmm Apr 13 '17 at 06:21

3 Answers3

0

With this query:

INSERT INTO Student(first, last, dob) SELECT first, last, dob FROM Student1

Change column names to the appropriate column names of each table.

Edward B.
  • 437
  • 3
  • 10
0

use this sql which help you

INSERT INTO Student(field1,field2,field3)
SELECT field1,field2,field2
FROM Student1;

you can use this code for ci

$query = $this->db->query('INSERT Student (field1, field2, field3)
                           SELECT field1, field2, field3
                           FROM Student');

this is format

INSERT INTO database2.table1 (field1,field2,field3) SELECT table2.field1,table2.field2,table2.field3 FROM table2;

for more information

https://dev.mysql.com/doc/refman/5.7/en/insert-select.html

Shafiqul Islam
  • 5,570
  • 2
  • 34
  • 43
0

For example
Student has id and name;
Student1 has id, firstname, lastname

You could fill Student by request:

INSERT INTO Student SELECT id, CONCAT(firstname, ' ', lastname) FROM Student1;

If Student is not empty, you could append records (change id to null, I assume that id column is autoincrement):

INSERT INTO Student SELECT null, CONCAT(firstname, ' ', lastname) FROM Student1;

agorlov
  • 1
  • 1