• Creating a special query

    Author
    Topic
    #1768482

    How would I be able to get my user to pull of all cities in a state. For example, if I wanted to put every city for every state in my database, what do I need to do to be able to pull up all cities in one state.

    Viewing 0 reply threads
    Author
    Replies
    • #1779630

      It could be as simple as a parameter query that asks for a state, if I understand your question.

      • #1779648

        How would I set up my tables for this? Do I created one table with all the states and under each state I put their cities? Or would I create 50 separate tables?

        • #1779650

          You need 2 tables:

          tblState has one record for each state. You could include fields for the state abbreviation and the spelled out state name.

          tblCity has one record for each city in a given state. That record would have a field for the city name, a field for the StateID (the primary key from the state table) for that City, and anything else you wanted to store about that city.

          • #1779711

            Charlotte, in the tblCity, you wouldn’t want a primary key field, would you? Just courious.

            frmorris, did Charlotte’s recommendation help?

            • #1779737

              Yes, you would. I didn’t include every field because I was trying to explain the relationship. The Primary Key for the state table would be a foreign key in the City table. But each city/state combination should have its own unique key, especially since city names are not unique.

            • #1779808

              Yes. Charlotte answer was a huge help. I have everything running smoothly now.

          • #1779807

            Thank you very much Charlotte. Your suggestion was a huge help. Everything is running smoothly.

    Viewing 0 reply threads
    Reply To: Creating a special query

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: