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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:02:03+00:00 2026-06-10T18:02:03+00:00

I have a resultset that is like this: ID | name | myvalue 1

  • 0

I have a resultset that is like this:

ID | name  | myvalue
 1 | A1    | 22
 2 | A2    | 22
 3 | A3    | 21
 4 | A4    | 33
 5 | A5    | 33
 6 | A6    | 10
 7 | A7    | 10
 8 | A8    | 10
 9 | A9    | 5

what i want, is to include only rows that contains the highest “myvalue” available (in the previous example is 33), then:

ID | name  | myvalue
 4 | A4    | 33
 5 | A5    | 33

IE the query should pick the highest “myvalue” available (IE 33) and it should remove the rows that have myvalue < 33

SELECT ..... WHERE myvalue = THE_HIGHEST_OF(myvalue)

Hoping to have been clear…

thank you in advance


edit:

my current query is

SELECT 
    *,
    (very long code that returns a integer as relevance score) AS myvalue
FROM
    mytable
HAVING
    myvalue = ?????
ORDER BY
    myvalue DESC

now the highest myvalue can be 10, 20, 30, any number… in the final resultset i want to include only the rows that have the highest possible relevance score

ive tried using GROUP BY, but i always need to repeat the…

    (very long code that returns a integer as relevance score) AS myvalue

…twice

  • 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-10T18:02:04+00:00Added an answer on June 10, 2026 at 6:02 pm
    SELECT * FROM t WHERE myValue IN (SELECT max(myValue) From t);
    

    ###See this SQLFiddle

    Edit:

    As per discussion with OP.
    OP wants to use alias in WHERE clause. But you can only use column aliases in GROUP BY, ORDER BY, or HAVING clauses.
    Look at this answer.

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

Sidebar

Related Questions

I have a query that creates a result set like this: Rank Name 1
Given that I have this resultset structure (superfluous fields have been stripped) Id |
In my mind I have a query that goes something like this: $sort =
I have a schema like this (simplified) var Language = new Schema({ name: String
I have an PHP array parsed from a JSON string that looks like this:
I have three tables like this: Table 1 structure: Name: registered_applicant_details Fields: applicant_id INT
I have a page that displays search results and has a DOM like the
I would like to have a stored procedure that return 3 results. these results
I have a SelectSP which returns resultset that i am storing in the temp
I have a result of a db query in java.sql.ResultSet that needs to be

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.