Jump to content

Recommended Posts

I admit my brain is refusing to accept this.  Can someone clarify?

 

Using this query on the MySQL world database (http://dev.mysql.com/doc/index-other.html) what relational structure is implied:

 

SELECT *

FROM Country

LEFT OUTER JOIN CountryLanguage ON Country.Code = CountryLanguage.CountryCode

LEFT OUTER JOIN City ON Country.Code = City.CountryCode;

 

The implied structure of the data is that Country is the parent and both City and CountryLanguage are children of that parent:

 

            Country

              /          \

            /              \

          /                  \

      /                      \

CountryLanguage  City

 

What concerns me is that the way the query is written partly implies that CountryLanguage is a child of Country and City is a child of CountryLanguage:

 

Country

    |

    |

CountryLanguage

    |

    |

City

 

The reason my brain refuses to accept this is the "what if" question of how to deal with a situation where I actually want that three level parent/child structure.  For example:

 

Surgery

    |

    |

Doctor

    |

    |

Appointment

 

Do I then just change the ON part of the query to reflect that or does the structure of the JOIN part affect it also?

 

I have the feeling that there will be a face-palm moment when someone explains or even when I read my own question tomorrow!

then your better read your question again and prepare your palm:

What concerns me is that the way the query is written partly implies that CountryLanguage is a child of Country and City is a child of CountryLanguage:

 

Country

    |

    |

CountryLanguage

    |

    |

City

 

this select

 

SELECT * 
FROM Country
LEFT OUTER JOIN CountryLanguage ON Country.Code = CountryLanguage.CountryCode
LEFT OUTER JOIN City ON Country.Code = City.CountryCode;

 

doesn't imply that in any possible way... the relations are clearly established in the JOINS.

 

Only in the order of the query words I guess.

 

So how do i create a query that does use the structure in the surgery - doctor - appointment example (where the third table is a child of the second and not the first)?

 

Palm is poised.

let me answer you with a hypothetical situation using a variation of the Country-City-Language example:

SELECT Country.name, City.name, CityLanguage.languagename 
FROM Country
LEFT OUTER JOIN City ON City.CountryCode = Country.CountryCode
LEFT OUTER JOIN CityLanguage ON CityLanguage.CityCode = City.CityCode;

 

that could represent a master-child-child relation... apply the same for the surgery-doctor-appointment example

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.