How to write SQL statement with dynamic where clause?

How to Write a SQL statement to display the repeated rows of the table below:?

  • Write a SQL statement to display the repeated rows of the table below: Field Type Null Key Default Extra doc_id varchar(1000) NO PARTIAL NO topic_id varchar(45) NO PARTIAL NO doc_headline text NO NO NO doc_text text NO NO NO

  • Answer:

    Ok, I will assume that 'topic_id' is the criteria for determining if the row is repeated (i.e. topic_id is the same on two or more items). I am giving you a generic way of dealing with the problem. You can adjust the query by changing the column name if the semantics of "repeated" are different: SELECT topic_id, count(topic_id) FROM documents GROUP BY topic_id HAVING count(topic_id) > 1

susil81 at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.