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

  • Home
  • SEARCH
  • 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 8120179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:03:12+00:00 2026-06-06T05:03:12+00:00

Consider the following query in HQL: SELECT m.id, (SELECT (COUNT(*) > 0) FROM SubqueryTable…)

  • 0

Consider the following query in HQL:

SELECT m.id, (SELECT (COUNT(*) > 0) FROM SubqueryTable...) FROM MyTable AS m;

I need to return information as boolean from the select query inside the select with information whether there are any entries that satisfy that query.

The above query would work fine translated in SQL, but hibernate gives me an error. I can’t use comparison operators with an aggregate function.

What is the proper way to get the information from the subselect inside the select clause, in HQL?

  • 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-06-06T05:03:15+00:00Added an answer on June 6, 2026 at 5:03 am

    Not sure how this can be transformed into HQL but your query could be written as:

    SELECT m.id,
           (SELECT COUNT(*) FROM SubqueryTable...) > 0
             AS b
    FROM MyTable AS m;
    

    But perhaps you could use this – which seems to be bypassing the problem as it is using INT columns:

    SELECT m.id,
           CASE WHEN (SELECT COUNT(*) FROM SubqueryTable...) > 0
               THEN 1
               ELSE 0
           END AS b
    FROM MyTable AS m;
    

    You could also try with EXISTS:

    SELECT m.id,
           EXISTS (SELECT * FROM SubqueryTable...) 
             AS b
    FROM MyTable AS m;
    

    or:

    SELECT m.id,
           CASE WHEN EXISTS (SELECT * FROM SubqueryTable...) 
               THEN 1
               ELSE 0
           END AS b
    FROM MyTable AS m;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following query: INSERT INTO statement_line_items SELECT count(*)::integer as clicks, sum(amount_cents)::integer as amount_cents,
Consider the following query: SELECT operation, [...] FROM tableName The operation field will retrieve
Please consider the following: $query = SELECT legIDs FROM trip; $result = mysql_query($query) or
Consider the following SQL Server 2005/2008 query: Select [UID], [DESC] From SomeTable Order By
Consider the following JPQL query: SELECT foo FROM Foo foo INNER JOIN FETCH foo.bar
Consider the following WSH snippet: var query = GetObject(winmgmts:).ExecQuery(SELECT Name FROM Win32_Printer, WQL, 0);
Consider the following query: SELECT domain, done FROM tasks WHERE 1 GROUP BY domain
Please consider following sample query SELECT * FROM subscriber WHERE subscription_date>DATE(NOW()-INTERVAL 10 DAY) My
Consider the following 3 standard statements $queryString = SOME SQL SELECT QUERY; $queryResult =
Consider the following Query : var profilelst = ( from i in dbContext.ProspectProfiles where

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.