Jump to content

INNER JOIN query problem


lilbadger25

Recommended Posts

I have acquired an already structured database for a page and they (as an afterthought) decided they would now like a CMS that would allow them to add products.

 

There are two databases:

 

products includes PID (id, obviously), prod_catID (the id of a category in the second table), prod_name, description, tech_info1, image, available, status

 

product_cat includes ID (matching the prod_catID in first table) and cat_name (the category name)

 

I have never joined tables before. I don't have time to restructure the db (pages have already been written) but I see the benefits of having the two tables.

 

For each row, I need PID, the category name (cat_name) associated with the number in the prod_catID field, description, tech_info1, image, available, and status

 

A friend of mine suggested using something like this:

	$query = "SELECT products.*, prod_catID as cat_name from products INNER JOIN product_cat ON products.prod_catID = product_cat.prod_catID";

 

but it's erroring Column: 'prod_catID' in field list is ambiguous

Link to comment
Share on other sites

I have never even seen a table alias before it was suggested. I took a look online for some tutorials and checked for the syntax in some of my books. Although I understand the theory, I am so confused as to how to write the select statement for this case. Additionally, do the aliases now become the variables?

Link to comment
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.