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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:22:09+00:00 2026-05-21T04:22:09+00:00

I have a query to fetch the top 50 entries based on a total_score

  • 0

I have a query to fetch the top 50 entries based on a total_score field. From these top 50, I need to be able to order them by any of their other fields. I tried using multiple ORDER BY statements, but the result set never changes. Here’s my query:

SELECT 
    e.id, e.name , e.total_score 
FROM 
    entry e 
ORDER BY 
    e.total_score DESC, e.name ASC

I think I understand why this doesn’t do what I need, so I suppose my question is how can I achieve my goal? In the end I always need the 50 entries with the highest total_score, but this selection should be then orderable by any other field.

If this isn’t possible in MySQL, I can do it with PHP, but I’d rather let the DB handle this.

Note: I’m using Doctrine 1.2 on top of a MySQL 5 DB.

Thanks!

  • 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-21T04:22:10+00:00Added an answer on May 21, 2026 at 4:22 am

    ORDER BY, when used with multiple columns, only uses the subsequent columns in case of tie in the previous ones.

    Try using nested queries

       SELECT * FROM(
        SELECT TOP 50
            e.id, e.name , e.total_score, e.(YOURFIELD)
        FROM 
            entry e 
        ORDER BY 
            e.total_score DESC ) x ORDER BY x.(YOURFIELD)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to fetch google images against any query. I have gone through the
I want to fetch the top 10 records from 2 tables which have id
I have the following select query, where I need to add an ORDER BY
I have this query to fetch the total OrderStatus that have values 1 and
I have the following code $result = $handle->select()->from('store_details') ->where('store_details.store_id=?', $id) ->columns('store_details.store_name'); //->query(ZEND_DB::FETCH_OBJ); However, when
I have query like this : SELECT EXTRACT(MONTH FROM d.mydate) AS synmonth, SUM(apcp) AS
i have a query to fetch 100 rows of events ordered by timestamp. i
I have this PHP code : $query = SELECT * FROM news WHERE news_active
I have these two SQL queries at the top of every page on my
I have to write a query which will display the top 25 game_id which

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.