Rewriting this Query with joins

  • Hi Folks,

    I want to rewrite this Query with joins for some reason I keep making some silly mistake and can't see how.

    If anyone can impart their knowledge its greatly appreciated!

    SELECT * FROM TransWorkDetail

    WHERE SalesLineItemId in (

    SELECT SalesLineItemId

    FROM TransLineItem WHERE TransHeaderID IN

    (SELECT TransHeaderID FROM TransHeader WHERE TransHeaderStatusCode = 'RAD'))

    Regards,

    M

  • Its OK guys I got it. sorry for being so stttooopppiiid...

    SELECT rwd.*

    FROM TransWorkDetail rwd

    JOIN SalesLineItemId rvl ON rvl.SalesLineItemId = rwd.SalesLineItemId

    JOIN TranHeader rh ON rh.TranHeaderID = rvl.TranHeaderID

    WHERE rh.TranHeaderStatusCode = 'RAD'

    if anyone cares...

  • Try:

    select twd.*

    from

    TransWorkDetail twd

    INNER JOIN TransLineItem TLI on twd.SalesLineItemId =tli.SalesLineItemId

    INNER JOIN TransHeader th on th.TransHeaderID =tli.TransHeaderID

    WHERE

    TransHeaderStatusCode = 'RAD'

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • I have been spending a lot of time rewriting older queries that utilize sub-selects in where clauses, much like the one that appears in this thread. I have seen some remarkable improvement in performance, as much as 2000% !!!

    I've actually had to give a training course to the developers to get them thinking of different way to recraft their SQL code to get better performance out of them.

    Kurt

    DBA

    RHWI, Inc.

    Poughkeepsie, NY

    Kurt W. Zimmerman
    SR DBA
    Lefrak Organization
    New York, NY

    http://www.linkedin.com/in/kurtwzimmerman

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

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