diff --git a/internal/query/instance.go b/internal/query/instance.go index 8a683d7f26..ba28bb6a24 100644 --- a/internal/query/instance.go +++ b/internal/query/instance.go @@ -291,7 +291,7 @@ func prepareInstancesQuery(ctx context.Context, db prepareDatabase) (sq.SelectBu return sq.Select( InstanceColumnID.identifier(), countColumn.identifier(), - ).From(instanceTable.identifier()). + ).Distinct().From(instanceTable.identifier()). LeftJoin(join(InstanceDomainInstanceIDCol, InstanceColumnID)), func(builder sq.SelectBuilder) sq.SelectBuilder { return sq.Select( diff --git a/internal/query/instance_test.go b/internal/query/instance_test.go index 27e206e0ee..decd687e29 100644 --- a/internal/query/instance_test.go +++ b/internal/query/instance_test.go @@ -55,7 +55,7 @@ var ( ` projections.instance_domains.creation_date,` + ` projections.instance_domains.change_date, ` + ` projections.instance_domains.sequence` + - ` FROM (SELECT projections.instances.id, COUNT(*) OVER () FROM projections.instances` + + ` FROM (SELECT DISTINCT projections.instances.id, COUNT(*) OVER () FROM projections.instances` + ` LEFT JOIN projections.instance_domains ON projections.instances.id = projections.instance_domains.instance_id) AS f` + ` LEFT JOIN projections.instances ON f.id = projections.instances.id` + ` LEFT JOIN projections.instance_domains ON f.id = projections.instance_domains.instance_id` +