dcsimg
www.webdeveloper.com
Results 1 to 2 of 2

Thread: Query on a Related Many Table

  1. #1
    Join Date
    Jul 2011
    Posts
    5

    Query on a Related Many Table

    Hi guys,

    I am new to SQL and I am learning fast, but I need some pointing in the right direction here, as I am not finding easily the answer to what should be a simple question.

    Say that we have 3 Tables with the following relationships:

    ------------ -------------- -------------
    | Cities | | States | | Countries |
    ------------ -------------- -------------
    | id | --->| id | --->| id |
    | name | | | name | | | name |
    | state_id |---- | country_id |---- | |
    ------------ -------------- -------------


    My question is,

    How do I structure a Query that would return all the Cities
    that belong to a certain Country?

    I look forward to some feedback.

    Thanks

  2. #2
    Join Date
    Jul 2011
    Posts
    5

    [resolved]

    Got it!

    And for future reference, here is how I got it working

    $calc = @mysql_query('SELECT SUM(points) FROM Cities, States WHERE Cities.state_id = States.id AND States.country_id = ' . $searchid . '');

    Hope this helps someone else in future!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles