Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.