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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:27:43+00:00 2026-06-10T09:27:43+00:00

I am trying to sort the result of my query by equality expression like

  • 0

I am trying to sort the result of my query by equality expression like

   ORDER BY (x = y) ASC

But I keep getting unexpected token =. I even tried things like

   ORDER BY COUNT(x = y) ASC

but with no success either: expecting CLOSE, found '='

Is there a way to achieve this with JPQL? Thanks

  • 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-10T09:27:44+00:00Added an answer on June 10, 2026 at 9:27 am

    No, it will not work that way with JPQL. It is not possible, because

    1. x=y is not orderable
    2. x=y is not part of SELECT clause.

    In JPA 2.0 specification this is told with following words:

    An orderby_item must be one of the following:
    
    1. A state_field_path_expression that evaluates to an orderable state field 
       of an entity or embeddable class abstract schema type designated in the 
       SELECT clause by one of the following:
         • a general_identification_variable
         • a single_valued_object_path_expression
    
    2. A state_field_path_expression that evaluates to the same state field of 
       the same entity or embeddable abstract schema type as a      
       state_field_path_expression in the SELECT clause
    
    3. A result_variable that refers to an orderable item in the SELECT clause 
       for which the same result_variable has been specified. This may be the 
       result of an aggregate_expression, a scalar_expression, or a 
       state_field_path_expression in the SELECT clause.
    

    What you can try is to use CASE in SELECT clause to construct numeric attribute and use that in ORDER BY.

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

Sidebar

Related Questions

I am trying to convert my query result to and order them according to
I am trying to sort query result into an array. I have following query.
I'm currently trying to order and sort by a key with three values. But
I'm trying to sort the employees object array by age and i'm getting the
Problem I have a YQL query result that I'm trying to get converted and
I'm having problems trying to get a query like this table answers CREATE TABLE
I am trying to create a query that will result in a list of
I'm trying to sort out a result set that gives the 5 closest users
When we run a Mongo find() query without any sort order specified, what does
i am trying to sort mysql data with alphabeticaly like A | B |

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.