SELECT "model"."brand_model_id" AS "modelId", MAX("endYear"."year_release_date") AS "latestReleaseDate" FROM "brands_models" "model" INNER JOIN "models_variants" "variant" ON  "model"."brand_model_id" = "variant"."brandModelBrandModelId" AND "variant"."deleted_date" IS NULL  INNER JOIN "variants_years" "endYear" ON  "variant"."model_variant_id"= "endYear"."yearVariantModelVariantId" AND "endYear"."deleted_date" IS NULL WHERE "model"."deleted_date" IS NULL GROUP BY "model"."brand_model_id"