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 531231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:16:46+00:00 2026-05-13T09:16:46+00:00

I want to get a distinct result based on a property, but return the

  • 0

I want to get a distinct result based on a property, but return the id in the select because I will be using it in a subquery.

e.g.

(List<Article>) session.createQuery("from Article a where a.id in (select distinct a2.title from article a2 where a2.body = :body");
setString("body", "")
.list();

The key section is the subquery, I want to return the id, not the a2.title property.
Can this be done?

(the table Article has duplicates, so I just want to return any one of them it doesn’t matter as long as the body = “”).

  • 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-13T09:16:47+00:00Added an answer on May 13, 2026 at 9:16 am

    If you don’t care which row is returned, you could change your subquery to:

    select MIN(a2.id) from article a2 where a2.body = :body
    

    This would return the lowest id from article where body matches.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get the distinct values in a list, but not by the
I want to get distinct Category and order there result by curdate column. select
Basically I'm trying to get a distinct count within this cubed result. But unfortuantly
I want to get the distinct value of a particular column however duplicity is
I have a query where i want to get a distinct description by the
I want to run a query to get a string array of distinct logName
I just want get a 2 dimension array of List in c#. In my
I want to get started doing some game development using Microsoft's XNA. Part of
I am trying to get distinct rows based on multiple columns (attribute1_name, attribute2_name) and
This might be confusing but what I want to do is a basic select

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.