a single query to achieve two sequential ones, is it possible?

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

    a single query to achieve two sequential ones, is it possible?

    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 | <----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 )? if so, i guess there would be some performance benefit.

  • ZeldorBlat

    #2
    Re: a single query to achieve two sequential ones, is it possible?

    On Jul 22, 2:56 pm, newbie <mitbb...@yahoo .comwrote:
    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 | <----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 )? if so, i guess there would be some performance benefit.
    select i.id, i.age, i.first_name, i.last_name,
    w.coming_date, w.work_hour
    from table_info i
    join table_working_h r w
    on i.id = w.id
    where i.first_name = 'tom'
    and w.coming_date 20

    Comment

    Working...