MySQL - 3 Table Join? (my brain hurts)

edited February 2008 in Internet & Media
MySQL problem:

Alright, here's the deal...

I've got two tables (tblComp, and tblTools)

tblComp
comp_id <- key
comp_name
comp_app

tblTools
tool_id <- key
tool_name
tool_desc
tool_details

tblComp houses details about specific components
tbltools houses details about specific tools

one component can have multiple tools
one tool can be used by multiple components
a tool will never exist without component
a component may exist without a tool

As is my understanding, 'relations' in MySQL are handled through the use of one JOIN or another.
Short of adding tool_id1, tool_id2, tool_id3... to the tblComp table, I don't see how this can be done with only two tables (or I'm donig something wrong).

I've built a 3rd (lookup) table called tblCompTool

tblCompTool
reference_id <- key
comp_id
tool_id

Maybe I'm just having a brain fart, but every join I've tried has failed to return the desired results (thus this message).
If you can provide any help with this, it'd be greatly appreciated.

Thanks.

Comments

  • edited February 2008
    After much headbanging, I believe I may have solved my own problem.


    select * from tblcomptool
    inner join tblcomp
    on tblcomp.comp_id = tblcomptool.comp_id
    inner join tbltools
    on tbltools.tool_id = tblcomptool.tool_id
Sign In or Register to comment.