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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:44:49+00:00 2026-05-28T07:44:49+00:00

I hope you will be able to help me, this has been giving me

  • 0

I hope you will be able to help me, this has been giving me headaches 😀

First, a bit of context:

Using the following table and data:

+-------------+---------+-------------+
| host_name   | service | last_change |
+-------------+---------+-------------+
| test.com    | PING    |  1327004398 |
| test.com    | HTTP    |  1327004536 |
| test.com    | MYSQL   |  1327004392 |
| test2.com   | PING    |  1327127720 |
| test2.com   | HTTP    |  1327004391 |
| test3.com   | PING    |  1327213842 |
| test4.com   | PING    |  1327004368 |
+-------------+---------+-------------+

What I’d lke to do is to print this out to a table with the host_name cell that spans the right amount of rows, a bit like so:

 +-------------+---------+-------------+
 | host_name   | service | last_change |
 +-------------+---------+-------------+
 |             | PING    |  1327004398 |
 | test.com    | HTTP    |  1327004536 |
 |             | MYSQL   |  1327004392 |
 +-------------+---------+-------------+

I am already able to do this, using a query that looks like this:

SELECT
    host_name,
    group_concat(service SEPARATOR '|') as service,
    group_concat(last_change SEPARATOR '|') as last_change,    

FROM table

GROUP BY host_name

And then by doing some manipulations (exploding results where pipes are found).

The problem I have:

I’d like to do the same thing but sort the results based on last_change. I tried to do the following:

SELECT
    host_name,
    group_concat(service SEPARATOR '|') as service,
    group_concat(last_change SEPARATOR '|') as last_change,    

FROM
(
    SELECT * FROM table ORDER BY last_change DESC
) as tmp_table

GROUP BY host_name

But it doesn’t seem to work. Changing the DESC to ASC doesn’t even change the results I get.

If I run the subquery that orders the results by itself, I get the expected results except the results arent grouped by host_name (obviously since it lacks the group_concat and group by statements).

Any ideas ?

I appreciate it A LOT.

  • 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-05-28T07:44:49+00:00Added an answer on May 28, 2026 at 7:44 am

    I didn’t get exactly what you’re trying to do here. Do you want results inside the group ordered, or the whole resultset?
    Try this for the first case:

    SELECT
        host_name,
        group_concat(service ORDER BY last_change DESC SEPARATOR '|') as service,
        group_concat(last_change ORDER BY last_change DESC SEPARATOR '|') as last_change
    FROM table
    GROUP BY host_name
    

    And this for second:

    SELECT
        host_name,
        group_concat(service SEPARATOR '|') as service,
        group_concat(last_change SEPARATOR '|') as last_change
    FROM table
    GROUP BY host_name
    ORDER BY table.last_change
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope somewhere out there will be able to help me on this. I
I really hope someone will be able to help me out with this. I
This is my first post here and I hope that someone will be able
hope this will be a quick easy question, I've just tried my app on
I hope I will find a help here. I have a quite complex MVC
I have little bit longer question for you - but hope answer will be
I hope this question will not be rejected as there is no code. But
I hope someone may be able to help! We have a pretty large VB.Net
please help me solve this issue. I have a client using WCF. I don't
I hope that if my question is out of context you guys will let

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.