For e.g., I have a MySQL table named "Qbank" which has following columns
I know how to get counts of repeated rows (Questions) -
SELECT Question,
Repeated,
count(ID) as cnt
FROM Qbank
GROUP BY Question
HAVING cnt > 1
And also, to get a list of all duplicate rows -
SELECT ID, Qbank.Question, Repeated FROM Qbank
INNER JOIN (
SELECT Question
FROM Qbank
GROUP BY Question
HAVING count(ID) > 1
) dup ON Qbank.Question = dup.Question
ORDER BY Question
But what I want to do is - to SET the "Repeated" value of all the duplicates (having same Question) to 1.
I.e. so that these can be differentiated from remaining non-duplicate questions, which have Repeated value 0 by default.
Sorry, for the elaboration, that was the only way to prove, that I have searched a lot before asking, and have not found anything yet.
Thanks.
Regards,
Dr. Atul
Try using JOIN
in UPDATE
:
UPDATE Qbank T1 JOIN
(SELECT Question FROM Qbank
GROUP BY Question HAVING count(ID) > 1) dup ON T1.Question = dup.Question
SET T1.Repeated = 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With