join query

  • 2 tables

    tblproduct

    shortsku varchar 5,

    edp int primary,

    name varchar 1000

    tblkit

    kitedp int primary,

    componentedp int

    i have shortsku value. there are be multiple records in tblkit for one shortsku(tblproduct.shortsku can also have multiple records). i need to query FSProducts for edp link to FSKits and then get all associated components and then tie each component back to a shortsku.

    the edp's form tblkit tie back to edp in tblproduct, meaning:

    tblproduct.edp = tblkit.kitedp &

    tblproduct.edp = tblkit.componentedp

    i need to get all records from tblkit where ed and tie the componentedp back to tblproducts.edp and get the shortsku

    for each record.


    </cm>

  • What is the requirement for edp (I'm assuming that's what you meant)?

    quote:


    i need to get all records from tblkit where ed and


    K. Brian Kelley

    bkelley@sqlservercentral.com

    http://qa.sqlservercentral.com/columnists/bkelley/

    K. Brian Kelley
    @kbriankelley

  • basically i need to take a given shortsku, look it up in tblproduct, from there get the edp and join that to tblkit and from there get the componentedp(s). i will then need to tie back to tblproduct and get the shortsku of each componentedp(where tblkit.componentedp=tbproducts.edp). make sense? thanks

    </cm>


    </cm>

  • If I am understanding your requirements...

    
    
    SELECT P2.shortsku
    FROM tblProduct P1
    JOIN tblKit K1 ON P1.edp = K1.kitedp
    JOIN tblProduct P2 ON K1.componentedp = P2.edp
    WHERE P1.shortsku = @sku

    Is that what you are looking for?

    K. Brian Kelley

    bkelley@sqlservercentral.com

    http://qa.sqlservercentral.com/columnists/bkelley/

    K. Brian Kelley
    @kbriankelley

  • yes. thank you for your patience and help.

    not sure what i would do without this site.

    -cm


    </cm>

  • Glad we could be of help.

    K. Brian Kelley

    bkelley@sqlservercentral.com

    http://qa.sqlservercentral.com/columnists/bkelley/

    K. Brian Kelley
    @kbriankelley

Viewing 6 posts - 1 through 5 (of 5 total)

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