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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:38:26+00:00 2026-06-15T10:38:26+00:00

OK, so I have gone through 14 Stack Overflow suggestions that were suggested when

  • 0

OK, so I have gone through 14 Stack Overflow suggestions that were suggested when I wrote this question, and I have tried everything, and can not figure this out.

I have a gym directory with reviews. I have a script that you can search through those gyms by Zip code, City/State or Neighborhood/City/State.

I have a few fields in the back end and in the database. The ones pertaining to this question are priority (I give it a number 1+ and it should show highest first or lowest first I don’t care which preferably highest to lowest), photo (it can have 5 photos), membership includes (a few things that the gym can include in the membership), and reviews (not editable but keeps count of how many review the gym has)

I would like to sort in this order

If the gym has priority, it should show first as it is prioritized. Null Priority should come last, Then sort by photo doesn’t matter a-z z-a just null comes last, then sort by membership includes null comes last, then sort by review count 0 or null comes last.

So if I have 4 gyms, A and B with priority, photo, and membership but 0 reviews, C with no priority, no photo, no membership, but highest review count at 2, and D with no priority but has photo and membership, but 1 review: it should sort in this order:

GYM   Priority   Photo      Membership   Reviews
A     yes        has some   has count    0
B     yes        has some   has count    0
C     no         no         no memb.     2
D     no         has some   has count    1

Expected sort order results: A B D C

Sorry of thats confusing.

Heres what I have already tried:

SELECT * FROM (SELECT * FROM gym WHERE (city = "Queens") AND (state = "NY") GROUP BY priority ORDER BY photo, member_includes, reviews DESC) x LIMIT 0, 150

SELECT * FROM (SELECT * FROM gym WHERE (city = "Queens") AND (state = "NY") ORDER BY priority, photo, member_includes, reviews DESC) x LIMIT 0, 150

SELECT * FROM (SELECT * FROM gym WHERE (city = "Queens") AND (state = "NY") GROUP BY photo, member_includes, reviews ORDER BY priority DESC) x LIMIT 0, 150

SELECT * FROM gym WHERE (city = "Queens") AND (state = "NY") GROUP BY photo, member_includes, reviews ORDER BY priority DESC LIMIT 0, 150

SELECT * FROM gym WHERE (city = "Queens") AND (state = "NY") ORDER BY priority, photo, member_includes, reviews DESC LIMIT 0, 150

And I have tried all other kinds of combinations with and without ASC but still it does not sort properly. I dont know what I am doing wrong.

Please help!

Thanks,
David

  • 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-15T10:38:27+00:00Added an answer on June 15, 2026 at 10:38 am

    I believe this is what you are looking for:

    SELECT * FROM gym
    WHERE city = "Queens" AND state = "NY"
    ORDER BY
      ISNULL(priority), priority,
      ISNULL(photo),
      ISNULL(member_includes), member_includes,
      ISNULL(reviews), reviews DESC
    LIMIT 150
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have gone through many posts on SO regarding this issue: Tried everything in
I've gone through various tutorials and Stack Overflow posts and understand that Selenium can
I have gone through several articles through this stack overflow and other related articles
I have gone through Google and Stack Overflow search, but nowhere I was able
I have gone through the fadein/fadeout tutorial that is on this page: For the
Ive gone through some of the previous posts on Stack Overflow before posting this.
I have gone through this wonderfull post on stackoverflow Validate IP address is not
I've gone through dozens of examples in Stack Overflow but I just can't quite
I've have gone through stackoverflow for days and googled a lot but can still
I have gone through this to change the color of my title bar. I'm

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.