Select DISTINCT individual columns in django?

One way to get the list of distinct column names from the database is to use distinct() in conjunction with values(). In your case you can do the following to get the names of distinct categories: q = ProductOrder.objects.values(‘Category’).distinct() print q.query # See for yourself. # The query would look something like # SELECT DISTINCT … 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