0

I am trying to find the keyword "img" in the duplicate values in my SQL database using the answer in this post: Finding duplicate values in a SQL table. I want to select those duplicate values in my database that have a "img" keyword in either of 'question', 'option' or 'solution' column.

My SQL statement looks like this:

SELECT
    `subject`, `topic`, `sub_topic`, `difficulty`,`question_number`,`question_version`, COUNT(*)
FROM
    `qz_question`
GROUP BY
    `topic`, `sub_topic`, `difficulty`,`question_number`,`question_version`
WHERE 
    `option` LIKE  '%img%' OR `question` LIKE  '%img%' OR `solution` LIKE  '%img%'

This returns me this error:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `option` LIKE '%img%' OR `question` LIKE '%img%' OR `solution` ' at line 7

How do I correct this error? Need some guidance on this.

Community
  • 1
  • 1
lakshmen
  • 28,346
  • 66
  • 178
  • 276

1 Answers1

1

your sql has some syntax error. I modified that error execute and see

SELECT
        `subject`, `topic`, `sub_topic`, `difficulty`,`question_number`,`question_version`, COUNT(*)
    FROM
        `qz_question`
    WHERE 
        `option` LIKE  '%img%' OR `question` LIKE  '%img%' OR `solution` LIKE  '%img%'
    GROUP BY
        `topic`, `sub_topic`, `difficulty`,`question_number`,`question_version`

These bottom SQL shows only duplicate records.

SELECT `subject`, `topic`, `sub_topic`, `difficulty`,`question_number`,`question_version`, COUNT(*) as c
    FROM
        `qz_question`
    WHERE 
        `option` LIKE  '%img%' OR `question` LIKE  '%img%' OR `solution` LIKE  '%img%'
    GROUP BY
        `topic`, `sub_topic`, `difficulty`,`question_number`,`question_version`
        HAVING c > 1; 

Thank you.

Venkatesh Panabaka
  • 2,064
  • 4
  • 19
  • 27