Jump to content

sqlite delete duplicate values

Recommended Posts


i am trying to isolate distinct values from a table into a temporary table

delete the original table

then rename the temporary table to the original table

here's what i have so far

_SQLite_Exec(-1, "SELECT DISTINCT Initials,Script,ScriptDirectory,Asset INTO TMPaScriptUpdater FROM aScriptUpdater")
    _SQLite_Exec(-1, "TRUNCATE TABLE aScriptUpdater")
    _SQLite_Exec(-1, "DROP TABLE aScriptUpdater")
    _SQLite_Exec(-1, "ALTER TABLE TMPaScriptUpdater RENAME TO aScriptUpdater")

im getting an error (from the first line):

near "INTO": syntax error

thanks in advance for your help!
Link to post
Share on other sites

This SQL looks pretty much like non-standard extensions. Neither SELECT ... INTO ... nor TRUNCATE are SQLite-ish.

Besides, this way of getting rid of duplicates doesn't recreate the exact same original table. For that you'd have to deal with index(es), triggers, constraints, foreign keys a.s.o.

A more straitforward way is to remove duplicates directly. Doing so without overlooking anything is best done after carfully examining your schema. Can you post it (the CREATE statements used for that table, its indices, constraints, triggers, FKs ...)?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to post
Share on other sites

actually i got it to work with this:

_SQLite_Exec(-1, "CREATE TABLE TMPaScriptUpdater AS SELECT DISTINCT Initials,Script,ScriptDirectory,Asset FROM aScriptUpdater")
_SQLite_Exec(-1, "DROP TABLE aScriptUpdater")
_SQLite_Exec(-1, "ALTER TABLE TMPaScriptUpdater RENAME TO aScriptUpdater")

thanks for your help =)

Edited by gcue
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...