Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with a script(SQL server)

Status
Not open for further replies.

Mo65

Computer
Joined
Sep 22, 2006
Messages
1
Location
US
I need help with a scripts
I want to creat an SQL scripts that go thru a table and
delete all the multiple entries and only keep one entry.

Table Addressbook
ID FirstName LastName City State Zip

thanks
Mo
 
Best method would be to create a new table:

Addressbook_temp

run a script thus:

insert into Addressbook_temp
select ID,FirstName,LastName,City,State,Zip from addressbook
group by ID,FirstName,LastName,City,State,Zip

delete the old table addressbook and then rename Addressbook_temp to Addressbook

Best method would be not to allow duplicates, via using a replace statement to insert data into your database. But that depends on the database you are using.


Technological progress is like an axe in the hands of a pathological criminal
 
Remove ID from the group clause else you'll obtain the same table. I believe is an ordinary Access base with ID assigned automatically.
Do not forget to assign a UNIQUE clause to the table for FirstName or FirstName and LastName or whatever field(s) you think it will be necessary, to avoid future record duplication.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top