*second edit with updated data*create table #yak (ID int, EntityID int, TypeID int) insert into #yak (ID, EntityID, TypeID)SELECT 1000, 500 ,1UNION SELECT 1001 ,500, 1UNION SELECT 1002 ,500, 2UNION SELECT 1003 ,500, 3UNION SELECT 1004 ,600, 2UNION SELECT 1005 ,600, 1UNION SELECT 1006 ,700, 1select * from #yakselect y.EntityID, y.id, y.typeidfrom #yak yinner join(select max(id)as id, entityidfrom #yakgroup by EntityID) zon y.ID = z.idand y.EntityID = z.EntityID drop table #yak
http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspxHow to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxFor ultra basic questions, follow these links.http://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp