insert into select statement for database
Hello guys !
I have created a table and insert a lot of records as the name of students of my college.The table is created with address age and blah columns.The Address field is much big.The problem is that I need to create another table which requires the same information to feed.Should I insert the whole record again in the second or any thing else.If you have any idea about the tools or commands Then suggest me .
thanks.
insert into select statement for database
Hello friend !
You have created a table but in which database you didn't specified.You have created another table that need the same information to insert.
There is no any tool and anything required to send your data from one table to another table .Commonly,In every database the insert into select statement is used to transfer the records from one table to another.
Before inserting the same records in second table,The datatypes and columns should be same as first table.Then after you can execute the query to insert the records in second table with appropriate arguments.
insert into select statement for database
The already created table named Colg_record has some columns named
Name varchar(25)
Age number(5)
Address varchar(120)
Create another table named tab_dup but should be same data type.After creating the table tab_dup,you can execute the following query statement to perform the insert operation for second table.
Code:
insert into tab_dup(name,age,address) select * from colg_record;
The whole table data would be transferred to the newly created table.
Combine Multiple Tables into One in PHP
You can combine multiple tables in one table in MySQL database to use the insert into select statement .
Suppose, when you require to combine a number of tables into one. you need just certain fields and columns from each of the table and then would adjust them together into a newly created table.
Code:
INSERT INTO Par_tab1 SELECT tab1.col1, tab1.col3, tab2.col2, tab2.col6 FROM tab1, tab2
The above code can be used in a PHP script to perform the same.
CREATE TABLE with SELECT statement in database
The SELECT statement can also be used create the table.Using the select statement,you can create another table which would be the clone of the back created table.It is commonly used to generate the reports from existing tables or performing the mixture.
The below expanded statement can be used to create another table using SELECT statement.The code would be as follows -
Code:
CREATE TABLE bbb SELECT col1, col2 FROM aaa;
Using the same way,you can create a table which would be the combination of more than one tables or tables column combination.
insert into select statement for database
The capability of the insert into select statement has increased according to the version evolutions.Not only MySQL,there are so many databases which uses this statement grown their capability of MySQL statement.
You can investigate it from the official websites of the databases using the documentation articles written by experts of database.