Search code snippets, questions, articles...

Insert data from one table to another in MySql

INSERT INTO tablename_1 ( 
    FullName, 
    EmailAddress,
    StatusNum
)
SELECT UserFullName, 
       EmailFromTable2, 
       '1'
FROM tablename_2
ORDER BY tablename_2_id ASC
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

The above code snippet can be used to insert rows from one table to another table. Here we are inserting rows into tablename_1 from tablename_2.

- UserFullName Column data from tablename_2 will be inserted into FullName column of tablename_1

- EmailFromTable2 Column data from tablename_2 will be inserted into EmailAddress column of tablename_1

- StatusNum column from tablename_1 will be assigned a value '1' in all rows.

Was this helpful?
0 Comments