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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:18:03+00:00 2026-06-04T12:18:03+00:00

Is it possible to order the results of an SQL query, on a field

  • 0

Is it possible to order the results of an SQL query, on a field that is not in the projection itself?

See example below – I am taking the distinct ID of a product table, but I want it ordered by title. I don’t want to include the title because I am using NHibernate to generate a query, and page the results. I am then using this distinct ID resultset, to load the actual results.

SELECT
DISTINCT this_.`ID` AS y0 
FROM
`Product` this_ 
LEFT OUTER JOIN
`Brand` brand3_ 
ON this_.BrandId=brand3_.ID 
INNER JOIN
`Product_CultureInfo` productcul2_ 
ON this_.ID=productcul2_.ProductID 
AND (
(
(
productcul2_.`Deleted` = 0 
OR productcul2_.`Deleted` IS NULL
) 
AND (
productcul2_.`_Temporary_Flag` = 0 
OR productcul2_.`_Temporary_Flag` IS NULL
)
)
) 
INNER JOIN
`ProductCategory` aliasprodu1_ 
ON this_.ID=aliasprodu1_.ProductID 
AND (
(
(
aliasprodu1_.`Deleted` = 0 
OR aliasprodu1_.`Deleted` IS NULL
) 
AND (
aliasprodu1_.`_Temporary_Flag` = 0 
OR aliasprodu1_.`_Temporary_Flag` IS NULL
)
)
) 
WHERE
(
this_._Temporary_Flag =FALSE
OR this_._Temporary_Flag IS NULL
) 
AND this_.Published = TRUE
AND (
this_.Deleted = FALSE
OR this_.Deleted IS NULL
) 
AND (
this_._ComputedDeletedValue = FALSE
OR this_._ComputedDeletedValue IS NULL
) 
AND (
(
this_._TestItemSessionGuid IS NULL 
OR this_._TestItemSessionGuid = ''
)
) 
AND (
productcul2_._ActualTitle LIKE '%silver%' 
OR brand3_.Title LIKE '%silver%' 
OR aliasprodu1_.CategoryId IN (
47906817 , 47906818 , 47906819 , 47906816 , 7012353 , 44662785 
)
) 
AND this_.Published = TRUE
AND this_.Published = TRUE
ORDER BY
this_.Priority ASC,
productcul2_._ActualTitle ASC,
this_.Priority ASC LIMIT 25;
  • 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-04T12:18:05+00:00Added an answer on June 4, 2026 at 12:18 pm

    Don’t know if there’s a better solution but how about a nested select where the external query exlude the field that you’re not interested in?

    So, something like that on a “random” table

    SELECT a,b,c from (SELECT a,b,c,d from myTable order by d)
    

    Obviously if there is a “language-direct” solution will be better because, in that way, you have to do two projection and one of those is useless

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

Sidebar

Related Questions

So I'm not the best at SQL I have this complicated MySQL query that
Possible Duplicate: SQL ORDER BY total within GROUP BY UPDATE: I've found my solution,
Possible Duplicate: Ordering by the order of values in a SQL IN() clause With
I'm using the below query to return results from a table using Full-Text-Search. In
I'm attempting to run an SQL query to display the results of a set
I have an sql query pulling a few results from different tables, one of
I have got a MySql query that orders me results by no column (int,
This SQL query gives me the results I want; however, I want the results
Possible Duplicate: Best way to prevent SQL Injection in PHP In the code below,
Possible Duplicate: Ordering by the order of values in a SQL IN() clause I

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.