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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:59:27+00:00 2026-06-03T11:59:27+00:00

In addition to the question How to concatenate strings of a string field in

  • 0

In addition to the question How to concatenate strings of a string field in a PostgreSQL 'group by' query?

How can I sort employee in descending order?

I am using PostgreSQL 8.4 which doesn’t support string_agg(). I’ve tried to use the following, but it isn’t supported:

array_to_string(array_agg(employee ORDER BY employee DESC), ',')

I’d appreciate any hint to the right answer.

  • 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-03T11:59:28+00:00Added an answer on June 3, 2026 at 11:59 am

    In PostgreSQL 9.0 or later you can order elements inside aggregate functions:

    SELECT company_id, string_agg(employee, ', ' ORDER BY company_id DESC)::text
    FROM   tbl
    GROUP  BY 1;
    

    Neither string_agg() nor that ORDER BY are available for PostgreSQL 8.4. You have to pre-order values to be aggregated. Use a subselect or CTE (pg 8.4+) for that:

    SELECT company_id, array_to_string(array_agg(employee), ', ')
    FROM  (SELECT * FROM tbl ORDER BY company_id, employee DESC) x
    GROUP  BY 1;
    

    I order by company_id in addition as that should speed up the subsequent aggregation.

    Less elegant, but faster. (Still true for Postgres 14.)

    See:

    • Concatenate multiple result rows of one column into one, group by another column
    • Alternatives to array_agg()?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In addition to this question: link i'm asking if i can retrieve data like
In C++, in addition to my question Erasing element from Vector , how can
I'm pretty sure you can, but in addition to answering the question in the
In addition to this question: iPhone network performance , I would like to know
In addition to my previous question , another problem appeared and I decided to
In my previous question , Andrew Jaffe writes : In addition to all of
In addition to the datastore for your specific site, can you also share one
This question bugged me for years now and can't seem to find good solution
I'm attempting implement the add method mentioned in the Generic sparse matrix addition question
If I have a valid SQL string; is there anyway I can execute it

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.