diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index e75ed43..8f733ef 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -715,6 +715,7 @@ protected function getOdnessQuery() protected function getDuplicatesQuery() { $table = $this->wrappedTable(); + $keyName = $this->wrappedKey(); $firstAlias = 'c1'; $secondAlias = 'c2'; @@ -726,7 +727,7 @@ protected function getDuplicatesQuery() ->newNestedSetQuery($firstAlias) ->toBase() ->from($this->query->raw("{$table} as {$waFirst}, {$table} {$waSecond}")) - ->whereRaw("{$waFirst}.id < {$waSecond}.id") + ->whereRaw("{$waFirst}.{$keyName} < {$waSecond}.{$keyName}") ->whereNested(function (BaseQueryBuilder $inner) use ($waFirst, $waSecond) { list($lft, $rgt) = $this->wrappedColumns();