Page 1 of 1

Complicated Join...

Posted: Fri Oct 24, 2008 12:38 pm
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?

Re: Complicated Join...

Posted: Fri Oct 24, 2008 2:13 pm
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.

Re: Complicated Join...

Posted: Fri Oct 24, 2008 6:41 pm
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