|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I worked with some developers awhile back for a company and recently found a problem with an update button, which caused data to be copied as many as 250 times. A table (measurements) holding data should have around 25,000 data points now has well over 500,000.
One table [Tasks] contains info about a block to be tested, such as an ID,desc, quantity to test. (taskID,Name,description,dimension1,quantity1, dim2,q2,d3,q3) There is a linking table [Pieces] which contains the fields [taskID] and [pieceID], because each taskID might have multiple pieces tested with many data points per test. Measurements table contains: pieceID, measurementID(AutoNum to make unique),dimNum, dataPoint. Each block can be tested in 3 dimensions thus there are 3 different quantity to test fields, but generally its just on the first, so I'm assuming the query just gets joined to another for each dimension. The question Basically I want to Select Top (quantity to test from tasks) for each pieceID in Measurements. Select All from measurements. Is this enough info/clear enough? Thanks in advance |
|
#2
|
||||
|
||||
|
Perhaps something like this would work?
Code:
SELECT *
FROM tasks, pieces, measurements
WHERE tasks.taskid=pieces.taskid
AND measurements.pieceid=pieces.pieceid
LIMIT 1
ORDER BY tasks.quantity DESC
|
|
#3
|
|||
|
|||
|
The problem I have is that there are "duplicates" in the measurements table. Like I should have 6 measurements. 6 were taken, then an error in my code caused copies to be made. So now I have a series of 6 data points repeating every 6 rows. The data points MIGHT be the same though (I might have 2 of the same data, but are not copies). So Top 6 would work, but sometimes its 10,12,24 measurements. The number of measurements is stored in the tasks.quantity1 field, but I can't get how to get that dynamic number out, I think in a subquery?
|
|
#4
|
||||
|
||||
|
so you're more interested in deleting the wrong data, than displaying the right data...
I assume you don't have a backup of the database? or a script to re-write the codes that is in the database? If you're using a programming language to interact with the database, you might want to make a simple program to interact with database. Perhaps display every row in the table, with chekcboxes, then you can quickly check the fields you want deleted... depending on your database system, you might already have a program that will connect and present data in this fashion already. On second thought, are you positive there's 10,000+ measurements in the table? Perhaps you just aren't joining the tables properly... try a simple SELECT COUNT(*) FROM measurements [and each other table]... If you were to use multiple tablse in the FROM clause, but not join the tables proplery in the WHERE clause, it will display a LOT more results than you expect. |
|
#5
|
|||
|
|||
|
|
#6
|
|||
|
|||
|
Would a relationship chart help?
|
|
#7
|
|||
|
|||
|
I'm not sure if this will help you, but from what I understand your problem to be, this is the approach I would take to resolve it.
I hope this helps. |
|
#8
|
|||
|
|||
|
I thought about running code to solve the problem, I was just know that a query would do the trick so nicely. I just don't know how to get the subquery to check how many measurements to take for each pieceID and then to run that query for the SELECT TOP for each record in the tasks.
|
|
#9
|
|||
|
|||
|
I finally figured it out. There is a help file in Access relating to "Delete Duplicates" that explains how to perfectly. I just never realized that my timestamp was the key to finding the duplicates. I didn't need much of a query at all, except for a simple append query mentioned in the help file. Its nice when F1 works.
|
![]() |
| Viewing: Dev Articles Community Forums > Databases > General SQL Development > Select Top (Subquery) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|