Column 'XXX' in field list is ambiguous

4

I'm having trouble executing the following Query:

 SELECT product_id,
       presentation
FROM Variant
INNER JOIN productCategory ON product_id = product_id
LIMIT 10;

Error:

ERROR 1052 (23000): Column 'product_id' in field list is ambiguous

How can I resolve using aliases?

    
asked by anonymous 12.12.2017 / 19:47

2 answers

7

This happens when we have the same column name in both tables, hence the error "ambiguous", so that the error disappears you must indicate in your select which table the column belongs to.

See:

SELECT
   Variant.product_id, 
   presentation
FROM Variant 
INNER JOIN productCategory 
ON productCategory.product_id = Variant.product_id 
LIMIT 10;
    
12.12.2017 / 19:53
1

Try this, my friend.

SELECT v.product_id, 
       presentation 
FROM Variant v 
INNER JOIN productCategory p 
ON v.product_id = p.product_id LIMIT 10;
    
12.12.2017 / 19:49