Jump to content

clause is ambiguous


dhope

Recommended Posts

Hi,

 

I'm trying to select three tables from my database to retrieve some information. But when I add more than one table I get the following error "Column 'user_id' in where clause is ambiguous".

 

I've tried a few different ways and had a read up online, but can seem to fix it. Please can someone point me in the right direction?

 

my code...

 

$page_settings = mysql_query("

SELECT *

FROM settings, seo, pages

WHERE user_id = '$user_id' ")

or die(mysql_error());       

$settings = mysql_fetch_array( $page_settings );

Link to comment
https://forums.phpfreaks.com/topic/211316-clause-is-ambiguous/
Share on other sites

Hi

 

If a column name is not unique in a SELECT you need to specify which table the column belongs to at any place you use the column.

 

ie

 

SELECT OWNER.NAME, DOG.NAME, OWNER.AGE, DOG.AGE

FROM OWNER

INNER JOIN DOG

ON OWNER.ID = DOG.OWNERID

 

Both the owner and dog tables have columns for name and age, hence you need to specify which one you are referring to

 

All the best

 

Keith

Link to comment
https://forums.phpfreaks.com/topic/211316-clause-is-ambiguous/#findComment-1101922
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.