Wondering if there is a way to insert a row into a table from another, with exception of one column?
This is of course easy with a limitied amount of columns, but gets kind of tiredsome listing all of the columns when the number of columns increases.
I'm thinking something in the line of:
Insert into table select * replace col1 with current date from table where yada yada yada
One possiblilty would be to duplicate one row and perform and update, but let's say that's not an option due to an index or something.
Any ideas?
Edit: It's DB2 v10, but the question is out of pure curiousity. Just wondering if it is possible...
COLUMNS table holds all information about the columns in your MySQL tables. To exclude columns, you use the REPLACE() and GROUP_CONCAT() functions to generate the column names you wish to include in your SELECT statement later.
It is also possible to only insert data in specific columns.
You can use a select-statement within an INSERT statement to insert zero, one, or more rows into a table from the result table of the select-statement. The select-statement embedded in the INSERT statement is no different from the select-statement you use to retrieve data.
You can use temporary tables
CREATE TEMPORARY TABLE temp_table AS (SELECT * FROM MyTable WHERE ...);
UPDATE temp_table SET column='Value' WHERE ...;
ALTER TABLE temp_table DROP column_name;
INSERT INTO MyDestinationTable SELECT * FROM temp_table;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With