© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
2 replies
Joakim

RPC that return result of joining to tables

I got two tables. one for products and one for stores and want to return a list of brands for the city id passed as a parameter, and also only those stores that has a is_listed value of true.
But I get an error saying
Failed to run sql query: column reference "city_id" is ambiguous
Failed to run sql query: column reference "city_id" is ambiguous

What does this error mean in my case?

here is my code:

create or replace function get_list_of_brands(city_id int)
returns void
as
$func$
Select brand from

(SELECT
brand, is_listed

from (

SELECT DISTINCT
product_table.brand as brand, stores_v3.store_id as storeID, stores_v3.city as city, stores_v3.is_listed as is_listed

FROM product_table
LEFT JOIN stores_v3 ON stores_v3.store_id = product_table.store_id 
LEFT JOIN city_table ON stores_v3.city_id = city_table.city_id where city_table.city_id = city_id

ORDER BY product_table.brand
) as TableBrand

where is_listed = true
) as Brand_AllStores
$func$
language sql;
create or replace function get_list_of_brands(city_id int)
returns void
as
$func$
Select brand from

(SELECT
brand, is_listed

from (

SELECT DISTINCT
product_table.brand as brand, stores_v3.store_id as storeID, stores_v3.city as city, stores_v3.is_listed as is_listed

FROM product_table
LEFT JOIN stores_v3 ON stores_v3.store_id = product_table.store_id 
LEFT JOIN city_table ON stores_v3.city_id = city_table.city_id where city_table.city_id = city_id

ORDER BY product_table.brand
) as TableBrand

where is_listed = true
) as Brand_AllStores
$func$
language sql;
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Joining 3 tables
SupabaseSSupabase / help-and-questions
3y ago
Bulk Insert RPC to return inserted values.
SupabaseSSupabase / help-and-questions
4y ago
RPC anon insert return ID
SupabaseSSupabase / help-and-questions
4y ago
How to return table row on RPC function?
SupabaseSSupabase / help-and-questions
3y ago