query ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- SELECT b."Id", b."Album", b."AlbumArtists", b."Artists", b."Audio", b."ChannelId", b."CleanName", b."CommunityRating", b."CriticRating", b."CustomRating", b."Data", b."DateCreated", b."DateLastMediaAdded", b."DateLastRefreshed", b."DateLastSaved", b."DateModified", b."EndDate", b."EpisodeTitle", b."ExternalId", b."ExternalSeriesId", b."ExternalServiceId", b."ExtraIds", b."ExtraType", b."ForcedSortName", b."Genres", b."Height", b."IndexNumber", b."InheritedParentalRatingSubValue", b."InheritedParentalRatingValue", b."IsFolder", b."IsInMixedFolder", b."IsLocked", b."IsMovie", b."IsRepeat", b."IsSeries", b."IsVirtualItem", b."LUFS", b."MediaType", b."Name", b."NormalizationGain", b."OfficialRating", b."OriginalTitle", b."Overview", b."OwnerId", b."ParentId", b."ParentIndexNumber", b."Path", b."PreferredMetadataCountryCode", b."PreferredMetadataLanguage", b."PremiereDate", b."PresentationUniqueKey", b."PrimaryVersionId", b."ProductionLocations", b."ProductionYear", b."RunTimeTicks", b."SeasonId", b."SeasonName", b."SeriesId", b."SeriesName", b."SeriesPresentationUniqueKey", b."ShowId", b."Size", b."SortName", b."StartDate", b."Studios", b."Tagline", b."Tags", b."TopParentId", b."TotalBitrate", b."Type", b."UnratedType", b."Width", u."ItemId", u."UserId", u."CustomDataKey", u."AudioStreamIndex", u."IsFavorite", u."LastPlayedDate", u."Likes", u."PlayCount", u."PlaybackPositionTicks", u."Played", u."Rating", u."RetentionDate", u."SubtitleStreamIndex"\r+ FROM library."BaseItems" AS b\r + LEFT JOIN library."UserData" AS u ON b."Id" = u."ItemId"\r + WHERE b."Id" IN (\r + SELECT (\r + SELECT b1."Id"\r + FROM library."BaseItems" AS b1\r + WHERE b1."Type" = $3 AND b1."IsVirtualItem" = $1 AND (b1."TopParentId" = ANY ($2) OR (b1."TopParentId" IS NULL AND array_position($2, $4) IS NOT NULL)) AND (b0."PresentationUniqueKey" = b1."PresentationUniqueKey" OR (b0."PresentationUniqueKey" IS NULL AND b1."PresentationUniqueKey" IS NULL))\r + LIMIT $5)\r + FROM library."BaseItems" AS b0\r + WHERE b0."Type" = $6 AND b0."IsVirtualItem" = $1 AND (b0."TopParentId" = ANY ($2) OR (b0."TopParentId" IS NULL AND array_position($2, $7) IS NOT NULL))\r + GROUP BY b0."PresentationUniqueKey"\r + )\r + ORDER BY b."SortName", b."Id", u."ItemId", u."UserId" (1 row)