Complicated Join...

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
jasonrfarrell
Forum Newbie
Posts: 1
Joined: Fri Oct 24, 2008 12:27 pm

Complicated Join...

Post by jasonrfarrell »

I'm having trouble wrapping my head around how to do this...

So I've got three tables, directors, commercials, commercial_categories

Each commercial has a director_id and a commercial_category

How do I query all the directors with their commercial_categories, but only if commercials exist in that director's category? The original programmer of the site never created a table that links directors to commercial_category. Is there any way around this?
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Complicated Join...

Post by jaoudestudios »

This should not be a problem, it is common. Can you post your database schema so we can see exactly what you need.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Complicated Join...

Post by aceconcepts »

You wont need a table that links directors with commercial categories - this link already exists by having directors related to a commercial, as commercials are then related with a cmmercial category.

One extremely good method for achieving your objective would be to use an INNER JOIN.

Take a look at this link for more info on joins http://www.w3schools.com/Sql/sql_join.asp
Post Reply