I’ll assume that your table is called “Contacts”
If you already have the data in the table and you just want to show the distinct rows (ie no repeated duplicates), then you can do this in SQLite:
select distinct * from Contacts;
to show just the two unique rows.
If you want to instead actually permanently remove the duplicates, you can use SQLite’s hidden “rowid” column to find all duplicate rows that aren’t the first row in a matching select:
delete from Contacts where rowid in
(
select rowid from Contacts as Duplicates where rowid >
(
select min(rowid) from Contacts as First
where First.Name = Duplicates.Name
and First.Place = Duplicates.Place
and First.Friend = Duplicates.Friend
and First.Pet1 = Duplicates.Pet1
and First.“Other Item” = Duplicates.“Other Item”
)
)
;
Just remove the encapsulating “delete” statement above. You can add the “*” the the select statement to show all the other columns (as well as the hidden rowid column) in the output:
select rowid, * from Contacts as Duplicates where rowid >
(
select min(rowid) from Contacts as First
where First.Name = Duplicates.Name
and First.Place = Duplicates.Place
and First.Friend = Duplicates.Friend
and First.Pet1 = Duplicates.Pet1
and First.“Other Item” = Duplicates.“Other Item”
)
;
Yes, I think it would be simpler, faster and best to check for duplicates when importing. It would take less time than checking after they’re all imported.
You can simply define a unique index:
create unique index “Contacts unique” on Contacts ( Name, Place, Friend, Pet1, “Other Item” );
and when you insert your data from the import, use the “insert or ignore” command, which will then ignore duplicate entries.
For many reasons, I suggest against creating and renaming tables as shown in another suggestion. You should confine ongoing data manipulation to the structure of existing tables.
For completeness, here is the SQL I used to create your sample table and data:
create table Contacts
(
Name text
, Place text
, Friend text
, Pet1 text
, “Other Item” text
)
;
insert into Contacts values ( ‘some name’, ‘some place’, ‘some friend’, ‘dogs name’, ‘cats name’ );
insert into Contacts values ( ‘some name’, ‘some place’, ‘some friend’, ‘dogs name’, ‘cats name’ );
insert into Contacts values ( ‘some name’, ‘some place’, ‘some friend’, ‘dogs name’, ‘cats name’ );
insert into Contacts values ( ‘another name’, ‘some place’, ‘another friend’, ‘birds name’, ‘cars name’ );
insert into Contacts values ( ‘another name’, ‘some place’, ‘another friend’, ‘birds name’, ‘cars name’ );
Tom
BareFeet
SQLite tools for Mac OS X compared:
http://www.tandb.com.au/sqlite/compare/