PDA

View Full Version : سوال: حذف داده های تکراری یک جدول



IMANAZADI
جمعه 04 اسفند 1391, 20:20 عصر
با سلام
فرض رو بر این میگذاریم که یک جدول داریم با یک فیلد نام
چطوری میشه DELETE QUERY نوشت که داده های تکرای نام رو پاک کنه
بطور مثال اگر در فیلد نام 4 نام یکسان وجود داشت 3 تا رو پاک کنه و یکی رو باقی بزاره
منظورم از DELETE QUERY گزینه ایی هست که وقتی یک کوئری ایجاد میکنیم یک قسمت بالای صفحه هست به نام DELETE کنار گزینه UPDATE, MAKE TABLE

hasanhzd
شنبه 05 اسفند 1391, 20:36 عصر
درود
بهتره یک کوئری maktable بسازید البته در زمان گذاشتن total باید دقت کنید و اسم فیلدهای کوئری رو هم خودتون باید بذارین که بعدا دچار مشکل نشین
بعد جدول جدید رو جایگزین جدول قبلی کنید

متن زیررواز کمک اکسس گرفتم با جستجوی delete duplicate البته همه کارهاشو میشه باکد یا ماکرو انجام داد اگه میخواید مستقیم با اشیاکار نکنید

Show All

Delete duplicate records from a table (MDB)
Note The information in this topic applies only to a Microsoft Access database (.mdb).

Deleting duplicate records from a table requires two steps. First, you create a copy of the structure of the table that contains duplicates, and then make primary keys of all the fields that contain duplicates. Second, you create and run an append query from the original table to the new table. Because fields that are primary keys can't contain duplicate records, this procedure produces a table without duplicate records.

Copy the table and make primary keys of fields with duplicates.
How?

In the Database window, click Tables under Objects.
Click the name of the table you want to delete duplicate records from.
Click Copy on the toolbar.
Click Paste on the toolbar.
In the Paste Table As dialog box, type a name for the copied table, click Structure Only, and then click OK.
Open the new table in Design view, and select the fields that contained duplicates in the table you copied.
Click Primary Key on the toolbar to create a primary key based on the selected fields.
Save and close the table.

********

Append only unique records to the new table.
How?

Create a new query based on the original table that contains duplicates.
In query Design view, click Query Type on the toolbar, and then click Append Query.
In the Append dialog box, click the name of the new table in the Table Name list, and then click OK.
Include all the fields from the original table by dragging the asterisk (*) to the query design grid.
Click Run on the toolbar.
Click Yes when you receive the message that you're about to append rows.
Click Yes when you receive the message that Microsoft Access can't append all the records in the append query. This transfers only unique records to your new table and discards the duplicates.
Open the table to see the results.
When you're sure the new table has the correct unique records, you can delete the original table, and then rename the new table using the name of the original table.

mazoolagh
یک شنبه 06 اسفند 1391, 12:40 عصر
احتیاجی به جدول جدید و ... نیست:

1- یک فیلد autonumber بنام ID به جدول اضافه کنین
2- کوئری زیر رو اجرا کنین (با فرض اینکه اسم جدول TBL و اسم فیلد FLD باشه)

delete from TBL where ID not in
(select first(ID) from TBL group by FLD)

hamid-nice
پنج شنبه 16 آبان 1392, 23:22 عصر
با سلام
اگر بیشتر از یک فیلد داشتیم و تعداد فیلد ها زیاد بوده و فیلد autonumber هم اصلا نمی خواهیم داشته باشیم آنوقت چه کنیم ؟ با حلقه یا ... نمی شود؟ ( البته می خواهیم که از هر رکورد تکراری تنها یکی بماند )
با تشکر

mazoolagh
دوشنبه 20 آبان 1392, 10:00 صبح
با باز کردن رکوردست و پیمایش تک تک رکوردها در حلقه هر شرط پیچیده ای قابل پیاده شدن هست.

ولی بهتر اینه که همون موقع data entry جلوی ورود داده های تکراری گرفته بشه.

hamid-nice
دوشنبه 20 آبان 1392, 10:11 صبح
با سلام
اکه امکان داره برای موضوع تاپیک یک نمونه ضمیمه کنید
با تشکر