sql - SQLplus: how to insert only if one of the columns is unique -
i have table 10 columns total, , need grab 6 of columns , insert them new table if 1 of columns unique.
i understand that:
insert table_1(col1, col2, col3) select distinct cola, colb, colc table_2; will give me rows combination of a, b, c unique, want insert unique , data associated in other columns of row. i've found exists , group aren't super clear me.
i trying...
insert table_1 (col1, col2, col3) select cola, colb, colc table_2 not exists (select cola table_2); ...cause me reads "insert cola, colb, , colc table_1 table_2 if cola not yet exist in table_2 i'm not sure if that's correct. thanks.
if "a unique" mean given value in "a" has 1 value, can use method:
insert table_1 (col1, col2, col3) select cola, max(colb), max(colc) table_2 group cola having count(*) = 1; the having clause finds values in "a" appear once. when there 1 row, max(colb) , max(colc)` return values row.
Comments
Post a Comment