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

  • Home
  • SEARCH
  • 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 8266659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:14:31+00:00 2026-06-08T05:14:31+00:00

I have a table sometable: name | math | history | status —————————– jon

  • 0

I have a table sometable:

name | math   | history  | status  
-----------------------------
jon  |   80   |   90     | 1  
alex |   90   |   70     | 1  
alex |   87   |   80     | 1  
jon  |   78   |   80     | 0  
alex |   90   |   60     | 1  
jon  |   30   |   100    | 0  
emile|   99   |   89     | 0  

what i want to do is get a row that name=alex, status=1 and have the maximal value for math, and then history for rows that satisfied. So the result will be

alex |   90   |   70     | 1  

I try code like:

select * from sometable where (name=$name and status=1) order by math DESC, history DESC

I got what i expect, since i can get the first row only of mysql_fetch_array.
But imagine how much the row in mysql_fetch array.

Yes, my code isnt false, but it is not enough “sophisticated” since it fetch many rows,Can anybody give a solution?
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-06-08T05:14:34+00:00Added an answer on June 8, 2026 at 5:14 am

    As long as you need only one row – use LIMIT 1 clause:

      SELECT *
        FROM tblname
       WHERE name = 'alex'
         AND status = 1
    ORDER BY math DESC
       LIMIT 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with sometable: name |test_date | score ----------------------- jon |2012:07:01| 95
I have a table with these fields: ID (Primary key) Name Some more data
I have two classes. I want to map Class1 to a database table with
I am using java/oracle. i have below issue. SELECT DISTINCT id_one, status FROM sometable
I have the table which list some details from database.I want to sort the
I want tho have I18N categories table. I have followed the jobeet example .
I have some table cells displaying different time. I want the time to be
I have some table 'TableName' like Id,Name: 1 | something 2 | _something 3
I have the name of an index that is existing on some table on
Database Name is ONLINEEXAM I have several tables in the db and I want

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.