RSS Forums RSS
Please support our MySQL advertiser: Programming Forums
Views: 2288 | Replies: 1
Reply
Join Date: Apr 2006
Posts: 1
Reputation: raffael is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
raffael raffael is offline Offline
Newbie Poster

Help Need Help Joining 3 tables

  #1  
Apr 22nd, 2006
Hi every one

I have 3 tables

department department_id, name, description
category category_id, name, description
product product_id, name, description

category belong to more then one department
product belong to more then one category also more then one department

I managed to show categories in selected department.

But I can't come up with sql query to show products that belong to a category that belong to a department.


// retrieves product that belong to the mentioned category
public function GetProductsInCategory($categoryId)
{
$query_string = "SELECT p.product_id, p.name, p.description
FROM product INNER JOIN department_category_product
ON p.product_id = department_categoy_product.product_id
WHERE department_category_product.department_id = 1
AND department_category_product.category_id = $categoryId";
$result = $this->dbManager->DbGetAll($query_string);
return $result;
}

the problem with this query, I have to mention department ID = 1

I tried this
WHERE department_category_product.department_id = department_id
now I am getting all the products that belong in the selected category
AND NOT in the selected department->category

Many, many thanks
Jovani
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2006
Posts: 5
Reputation: linkspub is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
linkspub linkspub is offline Offline
Newbie Poster

Re: Need Help Joining 3 tables

  #2  
May 1st, 2006
I'll give u 3 hints but i can't go through ur requirements and solve it for you since it would take a few hours for me to do it.

1)draw ur erd and figure out the relationships between the tables, ie 1 to 1, 1 to many or many to many.

2)think subselect

3)an alternate to the join keyword is the where keyword.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 7:13 pm.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC