Search code examples
mysqlsqlpostgresqlinner-joinredash

redash SQL query inner join with query


I am using redash to display data and am struggling to figure out how to show only specific images for this join query.

The problem is with my last AND condition which seems to break the query (AND "images"."imageable_type" = "BrandProfile"). Below is the error message I am receiving.

Error running query: column "BrandProfile" does not exist LINE 31: ...s"."height" = 760 AND "images"."imageable_type" = "BrandProf... ^


SELECT "brand_profiles"."company_name",
       "users"."full_name",
       "brand_profiles"."location",
       "brand_profiles"."company_website",
       "brand_profiles"."description",
       "images"."processed_url"
FROM "brand_profiles"
INNER JOIN "users" ON "users"."id" = "brand_profiles"."user_id"
INNER JOIN "images" ON "images"."imageable_id" = "brand_profiles"."id" AND "images"."height" = 760 AND "images"."imageable_type" = "BrandProfile"
WHERE "brand_profiles"."deleted_at" IS NULL
  AND "brand_profiles"."marketplace" = true

Solution

  • Could you try to replace "BrandProfile" with 'BrandProfile'. Also would recommend to read the post When to use single quotes, double quotes, and backticks in MySQL that explains how behaviour of ANSI_QUOTES mode.