去重取最新数据

Lambda:
var uLogQuery = db.cus_UserCRMLog.GroupBy(s => new { s.CRMUserID }).Select(g => g.OrderByDescending(p=>p.ID).FirstOrDefault()).toList();
SQL:
select * from table where id in (select max(id) from table group by [去除重复的字段名列表,....])

你可能感兴趣的:(去重取最新数据)