Huge performance difference when using GROUP BY vs DISTINCT

The two queries express the same question. Apparently the query optimizer chooses two different execution plans. My guess would be that the distinct approach is executed like: Copy all business_key values to a temporary table Sort the temporary table Scan the temporary table, returning each item that is different from the one before it The … Read more

How do you create a Distinct query in HQL

Here’s a snippet of hql that we use. (Names have been changed to protect identities) String queryString = “select distinct f from Foo f inner join foo.bars as b” + ” where f.creationDate >= ? and f.creationDate < ? and b.bar = ?”; return getHibernateTemplate().find(queryString, new Object[] {startDate, endDate, bar});

LINQ Distinct operator, ignore case?

StringComparer does what you need: List<string> list = new List<string>() { “One”, “Two”, “Three”, “three”, “Four”, “Five” }; var distinctList = list.Distinct( StringComparer.CurrentCultureIgnoreCase).ToList(); (or invariant / ordinal / etc depending on the data you are comparing)

How to display unique records from a has_many through relationship?

Have you tried to specify the :uniq option on the has_many association: has_many :products, :through => :orders, :uniq => true From the Rails documentation: :uniq If true, duplicates will be omitted from the collection. Useful in conjunction with :through. UPDATE FOR RAILS 4: In Rails 4, has_many :products, :through => :orders, :uniq => true is … Read more

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

Entity Framework select distinct name

Using lambda expression.. var result = EFContext.TestAddresses.Select(m => m.Name).Distinct(); Another variation using where, var result = EFContext.TestAddresses .Where(a => a.age > 10)//if you have any condition .Select(m => m.name).Distinct(); Another variation using sql like syntax var result = (from recordset in EFContext.TestAddresses .where(a => a.city = ‘NY’)//if you have any condition .select new { recordset.name … Read more

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