query optimization

  • i have a basic doubt.

    lets assume we have 2 tables.

    table1 has feilds id, name, age, sex, hieght, weight

    of which name and id are primary keys.

    table2 has fields name, id, address

    of which name and id are primary keys.

    now if i want to get address,age of everyne

    i can run queries

    1)select address, age from table2 t2, table1 t1 where t1.name = t2.name and t1.id = t2.id

    2)select address, age from table2 t2, table1 t1 where t1.name+t1.id= t2.name+t2.id

    both queries give the same result. i wanted to know which will be faster.

    can anyone help. thanks in advance

  • Sounds a bit like homework or an interview question, but I'll bite...

    In the presence of the correct indexes (composit primary key), the first one will probably be a little faster because it does no calculations on the indexed columns. Of course, how hard would it be for you to actually setup a test? 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply