home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

Access query problem

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 2371
Discussions: 200,942, Posts: 2,379,331, Members: 246,305
Old April 13th, 2002, 09:31 PM   Digg it!   #1 (permalink)
Junior Member
 
Join Date: Apr 2002
Posts: 7
Lightbulb
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.
SlipGun is offline   Reply With Quote
Old 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?
kakyoin is offline   Reply With Quote
Old April 14th, 2002, 02:10 AM     #3 (permalink)
Ultimate Member
 
fyxxer32's Avatar
 
Join Date: Nov 2001
Location: KansasCity
Posts: 1,312
I dont have an answer but WELCOME to Techimo!
fyxxer32 is offline   Reply With Quote
Old April 14th, 2002, 02:11 AM     #4 (permalink)
Senior Member
 
angelcat's Avatar
 
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
angelcat is offline   Reply With Quote
Old 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.
vass0922 is online now   Reply With Quote
Old April 14th, 2002, 11:22 PM     #6 (permalink)
Senior Member
 
Rhino's Avatar
 
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....
Rhino is offline   Reply With Quote
Old 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
vass0922 is online now   Reply With Quote
Old April 15th, 2002, 11:33 AM     #8 (permalink)
ph34r t3h g04t
 
Whir's Avatar
 
Join Date: Oct 2001
Location: Kingsford, MI
Posts: 19,555
Blog Entries: 7
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
Whir is online now   Reply With Quote
Old April 15th, 2002, 02:23 PM     #9 (permalink)
Member
 
thehig's Avatar
 
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
thehig is offline   Reply With Quote
Old April 15th, 2002, 10:24 PM     #10 (permalink)
Senior Member
 
Rhino's Avatar
 
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.
Rhino is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Making Health Care Worse (159)
The disrespect of Obama by Russian .. (14)
Wireless Televisions. (11)
windows 7 problem (7)
CPU fan stops spinning randomly (8)
Regular Build (6)
Is the PSU I received dead? (11)
Print spooler problem (15)
HIS HD5770 graphic card question (15)
windows vista security holes (9)
Install XP pro and a Vista laptop ?.. (11)
Foreign voltage (10)
Dept. of HS: NSA 'Helped' Develop V.. (15)
A good PSU? (10)
Recent Discussions
BSOD On Startup (ntoskrnl.exe) (2)
Print spooler problem (15)
Laptop with wireless problem. (1)
Wireless Televisions. (11)
Have you switched yet? (86)
Asus P4G8X Mobo (5)
screen resolution vs monitor size (2)
radeon x850xt platinum & shader 3 (4)
sms storage to PC (0)
Regular Build (6)
Open With ..... Win7 (0)
java code for fibonacci (1)
[F@H SPAM 11/16/09] ! 1/2 months to r.. (35)
windows 7 problem (7)
CPU fan stops spinning randomly (8)
Partition Magic caused HDD problem (3)
Is the PSU I received dead? (11)
Point and Shoot Camera Suggestions. (2)
Modern Warfare 2 freeze (13)
wireless user (1)
World's largest Monopoly Game using G.. (332)
Ideal cheap graph card for PC-Gaming? (17)
BIOS won't read disk when I try to fl.. (0)
Install XP pro and a Vista laptop ?? (11)
Graphics Card Upgrade Question (1)


All times are GMT -4. The time now is 05:32 PM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28