• Mark (6/24/2008)


    Another alternative

    SELECT

    A.RetailerID,

    X.RetailerIDTheirs

    FROM TableA AS A

    CROSS APPLY (SELECT TOP 1 B.RetailerIDTheirs FROM TableB B WHERE B.RetailerID = A.RetailerID ORDER BY B.RetailerIDTheirs ASC) AS X

    Nice one, Mark, and far closer to the OP's requirements. We're still on 2k here.

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden