Bigquery how to write a website. Using language php html css webmaster tips & tools BigQuery.com ready to experience. To make a simple site .. As a basis for writing website And add the finishing touches to the site. In addition, as an alternative to creating a site with a variety of tools.

Saturday, September 27, 2008

SQL INSERT .. SELECT sql command copy data from table to table

This SQL command may not use frequently. But I think should be have useful for some people, I'm talking about "INSERT INTO ... SELECT", The SQL Command for insert data to table from another data table

The Syntax of this SQL command is:
INSERT INTO "table1" ("column1", "column2")
SELECT "column3", "column4"
FROM "table2"

THE EXAMPLE
If you want to puts data from "Orders" table which is order purchased in 2007 to keep the other one, can create query like follow this:

INSERT INTO Orders2007(order_id, date_purchased, amount)
SELECT order_id, date_purchased, amount
FROM Orders
WHERE Year(date_purchased) = 2007;

That's it will get data which is order purchased in 2007 to "Order2007" table.
This SQL statement is like a copy to some records into another table.

No comments: