• faheemahmad14 (4/26/2013)


    Actually this issue was asked in an interview of mine and my answers were to use Row_Numbers, Cursors , functions etc . but they forced me to provide a solution without native powers of tool and to do this by using simple SQL.

    i threw this question here for my knowledge if there exists a solution for that.

    thanks

    I would ask them if they are in the habit of routinely limiting developers to not using all the facets of a tool. 😉

    Obviously what they want to understand is your knowledge of sql. The question is a very poor one imho. If you ask an interview question and ask someone to write code you shouldn't dictate they can't use powerful features of the language.

    This reminds me of a software developers test I took. They asked me to write a linked list in .NET, the instructions also explicitly stated NOT to use the native LinkedList object. I wrote the code example and about a half of diatribe about how ridiculous it is to ask to disallow using features of a language. Obviously, the reason the object was written into the framework is because it is a complete PITA to roll your own. Using windowed functions is much the same.

    Venting aside, you can do this without using "Row_Numbers, Cursors , functions etc". I did use an outer apply but this goes back to my previous comment.

    Much thanks to Steve Willis for putting together sample data and ddl. 😀

    delete #TempTable

    where ID not in

    (

    select x.ID

    from #TempTable t

    outer apply

    (

    select top 1 tt.*

    from #TempTable tt

    where tt.Event = t.Event

    and tt.ID <> t.ID

    order by tt.EventDate desc

    ) x

    where x.ID is not null

    group by x.ID

    )

    select * from #TempTable order by Event, EventDate desc

    _______________________________________________________________

    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/