crm crm - 11 months ago 57
SQL Question

Column 'user_id' in field list is ambiguous

I am attempting to get the user information of the user who left this review.

With the following code:

SELECT username, image, user_id FROM table_users AS us
JOIN table_reviews AS re
ON re.user_id = us.user_id
WHERE us.user_id = 1 AND
re.review_id= 1

I get the error:

Column 'user_id' in field list is ambiguous

What does this mean?

Answer Source

It means that both tables in the query have the column user_id.

You need to specify which one you want to get in the SELECT statement like SELECT username, image, re.user_id