This is what my query looks like:
select "spaces"."id" as "id",
"spaces"."user_id" as "user_id",
"spaces"."type" as "type",
"spaces"."latitude" as "latitude",
"spaces"."longitude" as "longitude",
"categories"."category_id" as "categories:category_id"
from "spaces"
left join "spaces_categories" as "categories" on "categories"."space_id" = "spaces"."id"
where "categories"."category_id" in ($)
and ST_DWithin(spaces.geometry::geography, ST_SetSRID(ST_Point($,$), 4326)::geography, $)
I am using pg 14.1
I am trying to find all spaces within a radius that meet the requested category Ids, along with all the categories for those spaces.
A space can have many category IDs, so if I search for category ids (1,2)
, and there happens to be 2 space results (and assume each space has 4 categories, 1,2,3,4
), I would be expecting 8 rows. However, my query only returns 4 rows, for categories 1,2.
How can I update my query so I can get all the categories, as long there is some overlap?
Is it due to my IN
clause?