Using SELECT to INSERT records in SQL
In MS SQL, very often I want to insert records into a table based on the record set of another query I have.
I always end up looking up this over and over, so here it is for your reference and mine.
(td_field1, td_field2) SELECT ts_field1, ts_field2 FROM table_source
Select and Insert or Update in MySQL
I forget this every time.
1. Select and Insert
INSERT INTO table1 ( table1.column1, table1.column2 ) SELECT table2.code, table2.name FROM table2;
2. Select and Update (actually, JOIN UPDATE)
UPDATE table1, table2 SET table1.column1 = table2.column1 WHERE table1.column_key = table2.column_key;