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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:37:49+00:00 2026-06-11T05:37:49+00:00

Is there a way to order your table by something that you don’t select

  • 0

Is there a way to order your table by something that you don’t select in the select clause such as:

Table Example

   Column  |    Type   |
-----------+-----------+
language   | character |
percentage | real      |
id         | integer   |

So I want to ideally do something like this

SELECT DISTINCT language FROM Example ORDER BY percentage DESC;

But this obviously doesn’t work. Is there a way that I can actually get it to order it by the percentage without actually selecting percentage in the SELECT clause?

This query

SELECT DISTINCT language 
FROM countrylanguage 
ORDER BY percentage DESC; 

gives this error message:

ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
LINE 1: ...T DISTINCT language FROM countrylanguage ORDER BY percentage...
  • 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-11T05:37:50+00:00Added an answer on June 11, 2026 at 5:37 am

    You don’t need to select a column to sort on it.

    create table language_pct (
      id integer primary key,
      language varchar(15) not null,
      percentage real not null,
      unique (language)
    );
    
    insert into language_pct values
    (1, 'English', 15.3),
    (2, 'French', 32.108),
    (3, 'Russian', 12.88);
    
    select language
    from language_pct
    order by percentage desc;
    
    French
    English
    Russian
    

    And if you had two rows for English, each with a different percentage, what would you have the dbms do for select distinct...?

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

Sidebar

Related Questions

Is there any way to use the order function on your table name. i.e
Is there any way to set order by clause in HQL by run time.
Is there any way to start foobar.js WSH-script in order that standard Task Manager
is there any way to use defined column name in SELECT statement with WHERE
is there any way to use defined column name in SELECT statement with WHERE
Is there a way in order to check if the page in question is
Is there is a way to order by the order of the values in
Is there a way to change tabs order in Vim (i.e. change the position
Is there a way to modify the printf in order to output string on
Is there a way to change the order of the controls inside a StackPanel

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.