Search code examples
phpmysqlsqlormpropel

How to find duplicate entries in database using Propel ORM?


I want to look for duplicate entries in my table and show all of them. How can I find all duplicated values in one column using Propel ORM?


Solution

  • Well, this question suggests using counts... you could replicate that query in Propel (I think) with this:

    $results = TableNameQuery::create()
      ->select(array("id", "field", "COUNT(*)"))
      ->groupBy("field")
      ->having("COUNT(*) > ?", 1)
      ->find();
    

    Of course, this gets a little hairy, so you might just want to use straight SQL if Propel fails you.

    (For reference, here's the SQL:)

    SELECT field, COUNT(*)
      FROM table_name
      GROUP BY field
      HAVING count(*) > 1