Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1092719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:43:31+00:00 2026-05-16T23:43:31+00:00

public class City { virtual public long Id { get; set; } virtual public

  • 0
public class City
{
    virtual public long Id { get; set; }
    virtual public string Name { get; set; }
}

City table contains duplicated Names and I want to remove duplicates. I also want the results to be ordered by Id.

First I thought about the following query.

select distinct Name from City order by Id;

But this breaks with ‘ORDER BY items must appear in the select list if SELECT DISTINCT is specified.’ exception. After seeing http://weblogs.sqlteam.com/jeffs/archive/2007/12/13/select-distinct-order-by-error.aspx I think I should do:

select Name from City group by Name order by min(Id)

So my question is how can I do this query with QueryOver?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:43:31+00:00Added an answer on May 16, 2026 at 11:43 pm

    This is possible in ICriteria:

    var list =
        session.CreateCriteria<City>()
            .SetProjection(Projections.Group("Name"))
            .AddOrder(Order.Asc(Projections.Min("Id")))
            .List<string>();
    

    But this is not currently possible in QueryOver, because the .OrderBy(IProjection) overload is missing. Once the missing overload has been added it should look something like:

    var list =
        s.QueryOver<City>()
            .Select(Projections.Group<City>(p => p.Name))
            .OrderBy(Projections.Min<City>(c => c.Id)).Asc
            .List<string>();
    

    Note that the Projections overloads are there just now, so you can write the following (typesafe) query in ICriteria:

    var list =
        session.CreateCriteria<City>()
            .SetProjection(Projections.Group<City>(c => c.Name))
            .AddOrder(Order.Asc(Projections.Min<City>(c => c.Id)))
            .List<string>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class Parent { private Integer Id; private String name; private String age; private
Why this does not work? public static class MyBean extends HashMap<String, String> { public
public class MyReportRenderer { private rs2005.ReportingService2005 rs; private rs2005Execution.ReportExecutionService rsExec; //string casenumberKey; public void
I've got a class with a city and country property, which I extend to
I want to access my applicant database that's why I created a DAO class
public class Example { public Example duplicate; public void duplicateState() { this.example = this.clone();
public class Constant { ...... public enum Status { ERROR, WARNING, NORMAL } ......
I have a custom vb,net class named Location with multiple properties. Example Class =
In the following list.java i am making a URL near the bottom that grabs
This is the Pseudocode I have written for a JAVA application to calculate distance

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.