I am trying to run a query that references 3 tables and return a field from one table. I am receiving an error saying ambiguous field even though i have tried to identify columns tables. I'm not sure with the whole code yet, because i can't get past the ambiguous error to test what i have so far.
Edit: Column 'supplier_id' in field list is ambiguous is the error i am receiving
Select supplier_id, company_name, country, sales_contact_name, email
FROM SUPPLIER, COFFEE, COFFEE_SHOP
Where SUPPLIER.supplier_id = COFFEE.supplier_id
and COFFEE.shop_id=COFFEE_SHOP.shop_id
and COFFEE_SHOP.city = "XXX";
In short, the output by default is ALL columns from 3 tables. When we specify the output column, if the same column name exists in more than one input tables, we need to explicitly tell query engine in [table_alias].[column_name] format.
Depend on your DB engine, the provided query will generate a product join, which is very resource consuming and in-efficient.
You can rewrite the query as below: