DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: Help writing a query

  1. #1
    Join Date
    Mar 2001
    Location
    New York , New York
    Posts
    577
    Hi,
    I have a address table with the following fields

    Address1
    Address2
    City
    StateId
    Zip
    CountryId

    and another table region with the following fields

    Region_id
    Region_Name
    Region_Type

    The state_id and Country_id in the address table are foreign keys to the region table where the states and countries are stored with a type of state . country.

    I want to write a query which will join these 2 tables and display the results as

    address1,address2,state,zip , country

    Note that i want to display the state and country names and not their Id's, in this case the region_name.

    I am having difficulty writing this query.

    please help.

    Thanks
    Ronnie

  2. #2
    Join Date
    Oct 2000
    Location
    Saskatoon, SK, Canada
    Posts
    3,925
    Code:
            SELECT A.address1,
                        A.address2,
                        A.City
                        B.region_name
                        A.Zip
                        C.region_name
            FROM Address_tbl A,
                     Region_tbl B,
                     Region_tbl C
             WHERE A.state_id = B.region_id
                     AND  A.country_id = C.region_id
                     AND  B.region_type IN ('State')
                     AND  C.region_type IN ('Country'); 
    You can refine the query by using the Italic phase lines, if you are sure of their types. Otherwise you can just ignore those lines and run your query.

    Sam

    [Edited by sambavan on 11-20-2001 at 03:22 PM]
    Thanx
    Sam



    Life is a journey, not a destination!


Posting Permissions

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


Click Here to Expand Forum to Full Width