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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:17:19+00:00 2026-05-31T21:17:19+00:00

I don’t think that I can use ORDER BY clause inside the GROUP_CONCAT function.

  • 0

I don’t think that I can use ORDER BY clause inside the GROUP_CONCAT function.

Does anyone know a tricky way to accomplish this behavior in SQLite?

I saw this question before. But I have a complex query .

My statement looks like this:

SELECT
    c.col1, c.col3, m.col3, m.col4,
    count(m.col1), count(re.col2) AS cnt,
    GROUP_CONCAT(p.col1 ORDER BY p.col1) AS "Group1",
    GROUP_CONCAT(p.col2 ORDER BY p.col1) AS "Group2", 
    GROUP_CONCAT(CASE WHEN con.col3 is null THEN p.col1 ELSE con.col3 END),
    con.col4, con.col5, p.col3
FROM t1 re
    INNER JOIN t2  c  ON (re.col1  = c.col1)
    INNER JOIN t3  p  ON (re.col2  = p.col1)
    LEFT JOIN  t4 con ON (con.col1 = p.col2)
    INNER JOIN  t5 m  ON (m.col1   = c.col5) 
GROUP BY re.col1 

Group1 and Group2 is coming from the same table but different columns: I want to preserve the order of the Group1 with Group2:

table t3 
+------+------+
| col1 | col2 |
+------+------+
|    1 | A    |
|    2 | B    |
|    3 | C    |
|    4 | D    |
|    5 | E    |
+------+------+

so if Group1 appears like this 2,1,3 Group2 should appear like this B,A,C

  • 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-31T21:17:20+00:00Added an answer on May 31, 2026 at 9:17 pm

    I have tried this and it make the work

    SELECT
        c.col1, c.col3, m.col3, m.col4,
        count(m.col1), count(re.col2) AS cnt,
        GROUP_CONCAT(p.col1 ORDER BY p.col1) AS "Group1",
        GROUP_CONCAT(p.col2 ORDER BY p.col1) AS "Group2", 
        GROUP_CONCAT(CASE WHEN con.col3 is null THEN p.col1 ELSE con.col3 END),
        con.col4, con.col5, p.col3
    FROM t1 re
        INNER JOIN t2 c   ON (re.col1  = c.col1)
        INNER JOIN (
            SELECT col1, col2, col3, col4, col5 FROM t3 ORDER BY col1
        ) AS          p   ON (re.col2  = p.col1)
        LEFT JOIN  t4 con ON (con.col1 = p.col2)
        INNER JOIN t5 m   ON (m.col1   = c.col5) 
    GROUP BY re.col1 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't know if anyone can help me with this or if it's even possible.
Don't think that I'm mad, I understand how php works! That being said. I
Don't know a whole lot about streams. Why does the first version work using
Don't think my virtualhost is working correctly. This is what I have inside of
Don't ask me why but i can't use this method because I need to
Don't know why I can't reply to people on here with only a small
I don't know Perl. I don't even love it, but i'm obliged to use
Don't know why but I can't find a solution to this. I have 3
Don't know the term for the red validation border, does it have one? I
Don't want to sort the entries. using this does not preserve the order as

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.