Wednesday, April 27, 2011

Insert data using select in sql

i has confuse how to insert data from another table. until i found this method by search in google.
this method can be used to copy table data
example:
you have table_a and table_b,
you want to copy data from table_a to table_b
this is the sql you can use:
insert into table_b (id, name, number)
select id, name, number
from table_a
that will copy all data from table_a to table_b.
you can use where if you want to copy data with specific condition.
insert into table_b (id, name, number)
select id, name, number
from table_a
where id<10
try it yourself,
and thanks for reading

No comments:

Post a Comment