• skb 44459 (8/23/2013)


    Here is the simplified query

    select

    m.trans_num ,

    m.trans_type ,

    m.lot

    from matltran m

    /*I want to find the top 1 record from same tables with 'WHERE trans_type = 'F' and lot = m.lot */

    inner join top 1 record of matltran table where trans_type = 'F' and lot = m.lot

    Top 1 as ordered by what?

    I don't even begin to understand what you mean by joining to the top 1 row. We don't join to rows, you join to a table. Why would you want to select 1 row and join it to itself? I think it would serve you well to post some solid details and a clear description of what you are trying to do.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/