DISTINCT ON in an aggregate function in postgres

The most simple thing I discovered is to use DISTINCT over jsonb (not json!). (jsonb_build_object creates jsonb objects) SELECT JSON_AGG( DISTINCT jsonb_build_object(‘tag_id’, photo_tag.tag_id, ‘name’, tag.name)) AS tags FROM photo LEFT OUTER JOIN comment ON comment.photo_id = photo.photo_id LEFT OUTER JOIN photo_tag ON photo_tag.photo_id = photo.photo_id LEFT OUTER JOIN tag ON photo_tag.tag_id = tag.tag_id GROUP BY … Read more

C# Distinct on IEnumerable with custom IEqualityComparer

The problem is with your GetHashCode. You should alter it to return the hash code of AllianceName instead. int IEqualityComparer<Village>.GetHashCode(Village obj) { return obj.AllianceName.GetHashCode(); } The thing is, if Equals returns true, the objects should have the same hash code which is not the case for different Village objects with same AllianceName. Since Distinct works … Read more

One-To-Many relationship gets duplicate objects without using “distinct”. Why?

This question is thoroughly explained on Hibernate FAQ: First, you need to understand SQL and how OUTER JOINs work in SQL. If you do not fully understand and comprehend outer joins in SQL, do not continue reading this FAQ item but consult a SQL manual or tutorial. Otherwise you will not understand the following explanation … Read more

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