Skip to content
Advertisement

SQLite Insert Distinct from 2 variables

I have a SQLite DB with a table with the following kind of data:

What I need to do is take columns B and C, create a single unduplicated list and autoincrement the primary key for the unique values. It needs to check to make sure an entry is not already existing – so the second table would be:

I think it should be something like this:

But I’m pretty sure that’s wrong. It needs to scan the table for duplicates prior to adding a new row and I’m getting stuck. I’m using a python program to load and modify my tables.

Advertisement

Answer

Use UNION to extract the values of the 2 columns.

UNION returns distinct values so there is no need for DISTINCT.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement