Access query problem  | |
April 13th, 2002, 09:31 PM
|
#1 (permalink)
| | Junior Member
Join Date: Apr 2002
Posts: 7
| Access query problem
I have a table with 3 fields that are of importance:
1) Item ID
2) A field with values set to either "Sale" or "Purchase"
3) Date of transaction
I have duplicate entries in this table for items that have been bought/sold many times over. Basically, I want to eliminate all duplicate entries for each item except for the one that has the highest date of them all - the latest transaction.
It's probably simple, but I'm new to this. |
| |
April 14th, 2002, 01:09 AM
|
#2 (permalink)
| | Member
Join Date: Oct 2001 Location: Austin, Texas
Posts: 39
|
what prog language you use?
is it ms access? |
| |
April 14th, 2002, 02:10 AM
|
#3 (permalink)
| | Ultimate Member
Join Date: Nov 2001 Location: KansasCity
Posts: 1,312
|
I dont have an answer but WELCOME to Techimo! |
| |
April 14th, 2002, 02:11 AM
|
#4 (permalink)
| | Senior Member
Join Date: Dec 2001 Location: Michigan, USA
Posts: 733
|
I don't know either, but I can offer a welcome to TechIMO!
__________________
Cats are angels with fur!
(\ /)
(O.o)
"
(> <)
Vorpal Bunny
|
| |
April 14th, 2002, 06:03 AM
|
#5 (permalink)
| | Not Really a Member
Join Date: Oct 2001
Posts: 25,386
|
Hmmm
Unfortunately the problem is not quite as easy as you'd like it to be!
First of all, before attempting this query MAKE SURE you are not working on the live data, its too easy to delete everything!!
First of all, lets set up a select query to see if we can get the correct data...
Tell ya what lemme think about it.. it may take a few steps and w/o the data will have to think about it, to see what we can do... there is a wizard in access that helps get rid of dupes, but not sure if it allows you to specify which ones to keep... will probably use the count(columname) function ...
also a welcome to TechIMO 
If you do figure it out, let us know for future reference 
I was thinking you could do a nested query, but not sure if it will be that easy... maybe somebody else can pop in an idea too 
__________________
Helicopters don't fly; they vibrate so much and make so much noise that the earth rejects them.
|
| |
April 14th, 2002, 11:22 PM
|
#6 (permalink)
| | Senior Member
Join Date: Oct 2001
Posts: 552
|
It might be safest for a select query on Item ID. Sorted by date, descending. Latest date should be at top. Make new query where date is less than that latest date. Change it to delete query and run.
__________________
It's like that, and it's like this....
|
| |
April 15th, 2002, 06:30 AM
|
#7 (permalink)
| | Not Really a Member
Join Date: Oct 2001
Posts: 25,386
|
Hmm rhino, that may not work...
If you sort by itemId you will get several ItemId's in a row of the same thing... plus you will have to define a date to cut it off and that's not real practical to get rid of ALL dupes.. would it work? partially
I'm assuming by the subject line this is an Access database, unfortunately writing a stored procedure in that involves writing a macro in VBA... not the same thing.
If you're good at writing macros you could make one that goes through each row (slow process) and looks for the itemid, queries a temp table if the itemid exists in that table... if it does not insert that row into the temp table... if it does exist then check for a newer date... if it is a newer date update the row with the new info or delete / insert
kind of a painful way to do it though  stinking Access
If you could group by ItemId and pick the one with the latest date that would wonderful, but if you group them including the date it'll return all of the dupes ... useless  |
| |
April 15th, 2002, 11:33 AM
|
#8 (permalink)
| | ph34r t3h g04t
Join Date: Oct 2001 Location: Kingsford, MI
Posts: 19,555
|
Do you have to delete the data? If all you need to know is the latest date an item was bought or sold, you could use a normal query inside Access. Just build your query, and sort it ascending by date. Then in the ItemID field you can set the field (in the query) to no duplicates. Then you'll only see the latest transactions done for that piece of inventory.
-Whir |
| |
April 15th, 2002, 02:23 PM
|
#9 (permalink)
| | Member
Join Date: Oct 2001 Location: NE Arkansas
Posts: 143
|
How do you want to handle multiple sales on the same date?Does the database assign the date which would include time or is it manual entered? If it includes time you have no problems. I think I can help you it will revolve around unique keys. Let us know if you need further help or if one of the above solutions will work.
__________________
Laziness is the mother of all invention. --the hig
|
| |
April 15th, 2002, 10:24 PM
|
#10 (permalink)
| | Senior Member
Join Date: Oct 2001
Posts: 552
|
First of all, what's the deal with wanting to get rid of duplicates? The only way I would see that happening is if you only had the one table. If that's the case, you need to make a table purely for Inventory....and another that has the Item ID, Date, (I would add time too), and sale/purchase. This way the Sales table would have all unique entries, with Item ID, Date, and Time together being the primary key. Then you wouldn't have to delete anything. You would have no probably with data redundancy that way. |
| | | Thread Tools | Search this Thread | | | | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |