Results 1 to 3 of 3

Thread: Same query to get data from more that one tables

  1. #1
    Join Date
    Jul 2006

    Same query to get data from more that one tables


    I have in the same database different tables:

    And so on...

    How can I in the same query in order to list me all the countries if meet the conditions sales=’1’ and active=’1’.

    I did:


    $connect = mysql_connect ("server", "username", "pass") or die ("bla...bla...");
    mysql_select_db($database, $connect) or die ("bla...bla...");

    $sql="select * from inter_main_".country." where sales = '1' and active = '1' group by country asc";
    $result = mysql_db_query("database", $sql);

    <? while($regist=mysql_fetch_array($result)){
    $arr=$regist ['country']; ?>

    <td><? echo substr($arr, 0,24); ?>.</a></b></td>

    <? } ?>

    This only gives me the list of countries in the country column that are in the same table: inter_main

    Last edited by JoseSilva; 03-06-2010 at 03:31 PM. Reason: RESOLVED

  2. #2
    Join Date
    Nov 2008
    The right question to ask is, "how do I normalize my database tables", and the answer is here. If you are forced to stick with your current structure you could UNION results from all three tables but you aren't really gaining anything much there. The cause of the issue is your database structure so I would suggest fixing that rather than trying to work around it.
    The first rule of Tautology Club is the first rule of Tautology Club.

  3. #3
    Join Date
    Jul 2006

    Thanks a Lot

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