tag:blogger.com,1999:blog-41682465629809350382018-03-02T07:34:21.330-08:00mari berkaryaKey Own Yanshttp://www.blogger.com/profile/15081084822501016491noreply@blogger.comBlogger1125tag:blogger.com,1999:blog-4168246562980935038.post-66524965835547171012014-06-11T21:57:00.002-07:002014-06-11T21:57:23.769-07:00INSERT INTOINSERT INTO "table1" ("column1", "column2", ...)<br />SELECT "column3", "column4", ...<br />FROM "table2";<br />Note that this is the simplest form. The entire statement can easily contain WHERE, GROUP BY, and HAVING clauses, as well as table joins and aliases.<br /><br />Assuming that we have the following tables:,<br /><br />Table <a href="http://photos-christmas.com/" target="_blank">Christmas Santa</a><br />Column Name<span class="Apple-tab-span" style="white-space: pre;"> </span>Data Type<br />Store_Name<span class="Apple-tab-span" style="white-space: pre;"> </span>char(50)<br />Sales<span class="Apple-tab-span" style="white-space: pre;"> </span>float<br />Txn_Date<span class="Apple-tab-span" style="white-space: pre;"> </span>datetime<br />Table Sales_Data<br />Column Name<span class="Apple-tab-span" style="white-space: pre;"> </span>Data Type<br />Store_Name<span class="Apple-tab-span" style="white-space: pre;"> </span>char(50)<br />Product_ID<span class="Apple-tab-span" style="white-space: pre;"> </span>integer<br />Sales<span class="Apple-tab-span" style="white-space: pre;"> </span>float<br />Txn_Date<span class="Apple-tab-span" style="white-space: pre;"> </span>datetime<br />Table Sales_Data has detailed sales information, while table Store_Information keeps summarized data on sales by store by day. To move data from Sales_Data to Store_Information, we would type in:<br /><br />INSERT INTO Store_Information (Store_Name, Sales, Txn_Date)<br />SELECT Store_Name, SUM(Sales), Txn_Date<br />FROM Sales_Information<br />GROUP BY Store_Name, Txn_Date;<br />Please note that we specified the order of the columns to insert data into in the example above (the first column is Store_Name, the second column is Sales, and the third column is Txn_Date). While this is not absolutely necessary, it is a good practice to follow, as this can ensure that we are always inserting data into the correct column.Key Own Yanshttp://www.blogger.com/profile/15081084822501016491noreply@blogger.com0