Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2008
    Posts
    24

    Unanswered: How would I go about joining these 4 tables?

    table 1 CustomerIDPK, countryIDFK, stateIDFK, Cust_Name. Address

    table 2 CustomerIDFK, Computer_Name

    table 3 stateIDPK, state

    table 4 countryIDPK, country

    How would I make the join in order to display specific information from each table in a query? for example: cust_name, computer_name, state, country

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    one does not write a query "to display specific information from each table"

    one writes a query to return data for a specific need

    what specific data were you looking for? customers in africa who don't have a computer? states which have no customers? the number of customer computers in each country?

    see, the permutations and combinations are endless, we cannot guess at what you want...
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Oct 2008
    Posts
    24
    The data I would need returned would be
    1. customer name
    2. country
    3. state
    4. computer name for that customer

    all this information spans over 4 tables
    customer table has information such as customer name, address. etc.
    country table has list with country name, etc.

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT table1.Cust_Name
         , table4.country
         , table3.state
         , table2.Computer_Name
      FROM table1
    INNER
      JOIN table2
        ON table2.CustomerID = table1.CustomerID
    INNER
      JOIN table3
        ON table3.stateID = table1.stateID
    INNER
      JOIN table4
        ON table4.countryID = table1.countryID
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Oct 2008
    Posts
    24
    ok got it, thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •