Column 'XXX' in field list is ambiguous

Asked

Viewed 3,622 times

6

I am 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 solve using alias ?

  • 1

    put the table name in front of the column.

  • 2

    As much as it’s a very basic mistake, I think a lot of people turn to know what’s going on, +1. I edited your question to give a little more visibility.

2 answers

10


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

Behold:

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

1

Try it like this, buddy.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.