How to implement IEqualityComparer to return distinct values?

An EqualityComparer is not the way to go – it can only filter your result set in memory eg: var objects = yourResults.ToEnumerable().Distinct(yourEqualityComparer); You can use the GroupBy method to group by IDs and the First method to let your database only retrieve a unique entry per ID eg: var objects = yourResults.GroupBy(o => o.Id).Select(g … Read more

How to get distinct results in hibernate with joins and row-based limiting (paging)?

You can achieve the desired result by requesting a list of distinct ids instead of a list of distinct hydrated objects. Simply add this to your criteria: criteria.setProjection(Projections.distinct(Projections.property(“id”))); Now you’ll get the correct number of results according to your row-based limiting. The reason this works is because the projection will perform the distinctness check as … Read more

MongoDB distinct aggregation

You can use $addToSet with the aggregation framework to count distinct objects. For example: db.collectionName.aggregate([{ $group: {_id: null, uniqueValues: {$addToSet: “$fieldName”}} }]) Or extended to get your unique values into a proper list rather than a sub-document inside a null _id record: db.collectionName.aggregate([ { $group: {_id: null, myFieldName: {$addToSet: “$myFieldName”}}}, { $unwind: “$myFieldName” }, { … Read more

PG::Error: SELECT DISTINCT, ORDER BY expressions must appear in select list

I know this is a rather old question, but I just went through a small example in my head which helped me understand why Postgres has this seemingly odd restriction on SELECT DISTINCT / ORDER BY columns. Imagine you have the following data in your Rsvp table: event_id | start_time ———-+———————— 0 | Mar 17, … Read more

How to use LINQ Distinct() with multiple fields

I assume that you use distinct like a method call on a list. You need to use the result of the query as datasource for your DropDownList, for example by materializing it via ToList. var distinctCategories = product .Select(m => new {m.CategoryId, m.CategoryName}) .Distinct() .ToList(); DropDownList1.DataSource = distinctCategories; DropDownList1.DataTextField = “CategoryName”; DropDownList1.DataValueField = “CategoryId”; Another … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)