how to have these two consequent queries become a single one by 'join' in mysql

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • newbie

    how to have these two consequent queries become a single one by 'join' in mysql

    --------------------------------------------------------- table_info
    | id | age | first_name | last_name |
    ---------------------------------------------------------
    | 10 | 21 | tom | ben |
    ---------------------------------------------------------

    ---------------------------------------------------------
    table_working_h r
    | id | coming_date | work_hour |
    ---------------------------------------------------------
    10 | 12 | 4 |
    ---------------------------------------------------------
    10 | 11 | 4 |
    ---------------------------------------------------------
    10 | 22 | 6 | <-------the
    will be the final result.
    ---------------------------------------------------------


    $result= mysql_query(" select * from table_info where first_name =
    'tom' ");
    $id = $result['id'];
    mysql_query(" select * from table_working_h r where id='$id' AND
    coming_date 20 ");

    Can I get the result with a single query (with some advanced query
    like join )?

  • nice.guy.nige

    #2
    Re: how to have these two consequent queries become a single one by 'join' in mysql

    While the city slept, newbie (mitbbsmj@yahoo .com) feverishly typed...

    [...]
    $result= mysql_query(" select * from table_info where first_name =
    'tom' ");
    $id = $result['id'];
    mysql_query(" select * from table_working_h r where id='$id' AND
    coming_date 20 ");
    >
    Can I get the result with a single query (with some advanced query
    like join )?
    mysql_query("se lect twh.* from `table_working_ hr` twh inner join
    `table_info` ti on twh.id = ti.id where ti.first_name = 'tom' and
    twh.coming_date 20");

    Hope that helps,
    Nige

    --
    Nigel Moss http://www.nigenet.org.uk
    Mail address will bounce. nigel@DOG.nigen et.org.uk | Take the DOG. out!
    "Your mother ate my dog!", "Not all of him!"


    Comment

    Working...