Self Join

  • Hi,

    I need help with a Self Join, I have a table with productID, groupID and version number all making up a composite primary key all of type int.

    I need to be able to query the table for latest version number in order to get the most current description of the product.

    I tried modifying the example found here http://qa.sqlservercentral.com/faq/viewfaqanswer.asp?categoryid=3&faqid=364   but that thing ran forever.

     

    Thanks in advance for any help you might provide.

  • SELECT T1.*

    FROM <Table> T1

    INNER JOIN (select productID, groupID, MAX(version) -- whatever method you use to identify the latest version

    from <Table>

    group by productID, groupID) T2 ON T1.productID = T2.productID AND T1.groupID = T2.groupID AND T1.version = T2.version

    _____________
    Code for TallyGenerator

  • Thank You!

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

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