How to insert the records in a table with where clause
How to insert the records in a table with where clause
I want to insert the values in a column of a same table, by the reference of another column values in same table by using wh开发者_运维技巧ere clause.
Insert into Table_1 (col_a, col_b)
select val_1, val_2 from dual
where 0 = (select count(*) from Table_1 where col_a = val_1);
This would prevent inserting the value twice.
To copy rows of the same table and specifying value for specific column:
INSERT INTO payment_tbl (col1, col2, col3) SELECT col1, col2, 'i_changed_value_of_col3' FROM payment_tbl WHERE item_description = 'vegetables'
To duplicate rows:
INSERT INTO payment_tbl SELECT * FROM payment_tbl WHERE item_description = 'vegetables'
精彩评论