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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:49:35+00:00 2026-05-24T17:49:35+00:00

I need some help on a MySQL SELECT statement. Unfortunately, this statement doesn’t work

  • 0

I need some help on a MySQL SELECT statement. Unfortunately, this statement doesn’t work correctly. It appears to rank based on alphabetical order of the school name instead of reading_percent_proficient_and_advanced. How should I fix it?

SET @rank=0;
SELECT @rank:=@rank+1 as rank, 
       sy.formatted_school_name, 
       FLOOR(d.reading_percent_proficient + d.reading_percent_advanced) AS reading_percent_proficient_and_advanced 
FROM d_test_scores AS d, 
       sy_2010_2011_school_type AS sy  
WHERE sy.school_id = d.school_id 
       AND sy.school_group = 'public school'
       AND sy.school_type ='elementary' 
ORDER BY reading_percent_proficient_and_advanced DESC

If I take out the join, then this statement gives me the correct ranking (but I don’t have the school names then):

SET @rank=0;
SELECT @rank:=@rank+1 as rank,  
       d.school_id, 
       FLOOR(d.reading_percent_proficient + d.reading_percent_advanced) AS reading_percent_proficient_and_advanced  
FROM d_test_scores AS d 
ORDER BY reading_percent_proficient_and_advanced DESC;

What’s the problem with my join?

  • 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-24T17:49:36+00:00Added an answer on May 24, 2026 at 5:49 pm

    (Speculation) I believe the rank is being calculated before the ORDER BY ordering is enforced. While in the original query, it just happened that your results came back in the order you wanted before the ORDER BY and thereby the rank was correct, in the advanced query the results are initially coming back in a different order.

    Try adding the rank to an already ordered set (subquery) of school name and proficiency ratings.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help with a mySQL statement. I've got a mySQL table that
I need some help optimizing a MySQL query or table When I run this
i need some help with this sql query heres my mysql table structure: DOMAINS
I need some help in mysql statement Ive table1 with 7 column and table
I need some help with a group by mysql query clause. Medals Table (this
I need some help in converting my script from using mysql to mysqli I
I'm very new to MySQL so I need some help please, I have a
I need some help on a MySQL query I'm trying to set up. I
I need some help figuring out why the following scenario does not work. I'm
Spent a few hours on this and need some expert help. I have a

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.