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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:27:30+00:00 2026-05-17T16:27:30+00:00

Further to a recently answered question, I have the following code: SELECT q21coding, COUNT(q21coding)

  • 0

Further to a recently answered question, I have the following code:

SELECT   q21coding, COUNT(q21coding) AS Count 
FROM     tresults_acme 
WHERE    q21 IS NOT NULL AND q21 <> '' 
GROUP BY q21coding
ORDER BY IF(q21coding = 'Other', 1, 0) ASC, Count DESC

It brings back the following:

q21coding                                  Count 
Difficulty in navigating/finding content     53
Positive comments                            28
Suggestions for improvement                  14
Inappropriate content/use                    13
Improve search facility                       6
Include information about staff and teams     5
Content needs updating                        4
Other                                        30

You’ll notice that Other is now at the bottom – However is there a way of ensuring that Positive comments and Other is ALWAYS the bottom two (with other at the bottom) regardless of the Count size?

Thanks,

Homer

  • 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-17T16:27:31+00:00Added an answer on May 17, 2026 at 4:27 pm

    Actually there was no need to use IF(q21coding = 'Other', 1, 0) in your original query. In MySQL you can use any expression in the ORDER BY caluse and q21coding = 'Other' would have been enough:

    ... ORDER BY q21coding = 'Other', Count DESC
    

    The q21coding = 'Other' expression will return 1 if true, or 0 if false. That will put rows with a q21coding = 'Other' at the bottom.

    What you need to do to have ‘Positive Comments’ and ‘Other’ both at the bottom is something like this:

    ... ORDER BY q21coding = 'Other', q21coding = 'Positive comments', Count DESC
    

    Basic test case:

    CREATE TABLE my_table (id int, q21coding varchar(100), count int);
    
    INSERT INTO my_table VALUES (1, 'Inappropriate content/use', 13);
    INSERT INTO my_table VALUES (2, 'Other', 30);
    INSERT INTO my_table VALUES (3, 'Difficulty in navigating/finding content', 53);
    INSERT INTO my_table VALUES (4, 'Positive comments', 28);
    INSERT INTO my_table VALUES (5, 'Improve search facility', 6);
    INSERT INTO my_table VALUES (6, 'Content needs updating', 4);
    INSERT INTO my_table VALUES (7, 'Suggestions for improvement', 14);
    INSERT INTO my_table VALUES (8, 'Include information about staff and teams', 5);
    

    Result:

    SELECT    q21coding, count
    FROM      my_table
    ORDER BY  q21coding = 'Other', q21coding = 'Positive comments', Count DESC;
    
    +-------------------------------------------+-------+
    | q21coding                                 | count |
    +-------------------------------------------+-------+
    | Difficulty in navigating/finding content  |    53 |
    | Suggestions for improvement               |    14 |
    | Inappropriate content/use                 |    13 |
    | Improve search facility                   |     6 |
    | Include information about staff and teams |     5 |
    | Content needs updating                    |     4 |
    | Positive comments                         |    28 |
    | Other                                     |    30 |
    +-------------------------------------------+-------+
    8 rows in set (0.00 sec)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a WCF service that we recently switched from self-hosting to IIS-hosted. It
i recently asked this question on how to have a container div width set
Further to this question and this one that I asked more recently but without
I've been updating recently to django 1.3 and got the following issue: I have
I've recently learned core Java and want to develop my skills further with practice
Background (question further down) I've been Googling this back and forth reading RFCs and
This is a further question based on this answer: How can I implement a
To continue to question further I'm more interested in blogs, websites who once in
I am trying to further a question I asked yesterday where I wanted to
I recently reimaged my PC and regrabbed one of our projects from Source Safe.

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.