delete only 1 instance of each record that has more than 1 example

E

efandango

I have a quiz setup that uses a rolling (never ending) score system based on
repetitive questions. The user is presented with a small, set number of
questions (but taken from a much larger master list); these questions are
randomly generated, and often get repeated (which is intentional).

Sometimes the user gets them right first time, other's he needs to be asked
a few times before he can answer the tougher one's correctly. In the
scenario, he answers 18 questions, and then hits the update button which
triggers a 2nd query/form that updates the scores and presents him with a
list of answers that he failed to get right.

The Questions form is cleared, and another 18 questions are presented, many
of which can be repeats of previous questions; but this time around he may
guess the previously wrong answers correctly, so I want some way of taking
the latest correct answers and finding just 1 of each matching previously
incorrect answers and deleting that incorrect answer, this then gives the
user a realistic view of his overall progess and an incentive target to aim
for. which means as time goes by, he will eventually whittle the list down to
no incorrect answers.

This is my results table:

Run_point_Venue Run_point_Address Correct Incorrect

Tower Bridge Square Queen Elizabeth Street, SE1 1 0
Tower Bridge Square Queen Elizabeth Street, SE1 0 1
Townley Clinic 121 Townley Road, SE22 1 0
Trafalgar Tavern Park Row, SE10 1 0
Trellick Tower 5 Golborne Road, W10 0 1
Trellick Tower 5 Golborne Road, W10 1 0

This is my query:

SELECT QX_Score_Points_Results.Run_point_Venue,
QX_Score_Points_Results.Run_point_Address, QX_Score_Points_Results.Correct,
QX_Score_Points_Results.Incorrect
FROM QX_Score_Points_Results;
 
G

Graham R Seach

Assuming each record has a primary key called "Run_point_ID" (if it
doesn't - create it!), then the following will do it for you. There's
probably a more efficient method, but this is the best I can offer.

DELETE * FROM QX_Score_Points_Results
WHERE Run_point_ID IN
(SELECT Q1.Run_point_ID
FROM QX_Score_Points_Results AS Q1 INNER JOIN
QX_Score_Points_Results AS Q2 ON (Q1.Run_point_Venue =
Q2.Run_point_Venue)
AND (Q1.Run_point_Address = Q2.Run_point_Address)
AND (Q1.Incorrect = Q2.Correct) AND (Q1.Correct = Q2.Incorrect)
WHERE Q1.Incorrect<>0)

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
Top