0

I need to insert into a table unique data for all cells. My table has 3 columns and I need to ignore insert if all 3 cells has the same value.

for example I have the table: |column_1|column_2|column_3|

and the values for this table:

  1. |val1|val2|val3|
  2. |val1|val2|val5|
  3. |val1|val2|val3|
  4. |val1|val2|val3|

So I need to be inserted only values 1 and 2 because 3 and 4 are the same as 1. I need this to be done in Sqlite v3.9.

Choletski
  • 7,074
  • 6
  • 43
  • 64

1 Answers1

2

You can insert the distinct values from source table into the destination table, something like this:

INSERT INTO NewTable (coulmn_1, column_2, column_3)
SELECT DISTINCT 
    column_1, 
    column_2, 
    column_3
FROM OldTable
dbajtr
  • 2,024
  • 2
  • 14
  • 22