to join or not to (inner)join

  • i need you advice on something....

    which is better

    lets suppose i have to write a querry wich needs only a column from(each) lets say 10 tables.

    which is better to do :

    A:

    select

    (select columnA from tblX Y where X.id = Y.id)

    ,(select columnB from tblZ Z where Z.id = Y.id)

    ,(select columnC from tblQ Q where Q.id = Y.id)

    etc

    or join this tables (10 of them) and i only need a column of each ...so it will look like

    select .....

    from

    Y

    inner join X

    inner join Z

    inner join q

    ............ etc

    I know that this query wont be fast , but i need the lesser evil from these two

    thank you

  • Option B (inner Joins) will kick the pants of option A performance wise. Option A should be avoided at all costs - you might as well use a cursor because it's essentially doing the same thing.

  • I know this will sound contrite but one of the fundamental facts of performance tuning is that you learn by actually doing it!!

    If you try the two methods you will know for yourself, it may also lead you into other elements of tuning as you examine the i/o and query plans.

    [font="Comic Sans MS"]The GrumpyOldDBA[/font]
    www.grumpyolddba.co.uk
    http://sqlblogcasts.com/blogs/grumpyolddba/

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

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