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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:18:46+00:00 2026-05-14T04:18:46+00:00

we want to have the second biggest element. We first use ANY to exclude

  • 0

we want to have the second biggest element. We first use ANY to exclude the biggest one. Then we use all to select the biggest. However when we run this query, it shows the biggest and not the second one. Why?

SELECT * 
FROM bestelling
WHERE totaalprijs > ALL
(
    SELECT totaalprijs
    FROM bestelling
    WHERE totaalprijs < ANY
    (
        SELECT totaalprijs
        FROM bestelling

    )
)

elements in the table:

157.00
5.00
82.80
15.00
20.00
20.00
  • 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-14T04:18:47+00:00Added an answer on May 14, 2026 at 4:18 am

    The problem is the “>” in your outermost query. If you break this down in language, from the inside out, you’re saying:

    • From all the rows in the table …
    • Get me any where totaalprijs is less than some other value (i.e. all records except records with the max value in the table, 157.00) …
    • Then, get me any values that are bigger than all the records in the previous table. Which is, naturally, just the biggest one.

    If you just want the second biggest value, you can replace that outer clause with a MAX statement:

    SELECT max(totaalprijs)
    FROM 
    (
        SELECT totaalprijs
        FROM bestelling
        WHERE totaalprijs < ANY
        (
            SELECT totaalprijs
            FROM bestelling
        )
    ) M
    

    Or, if you want all records that bear that “second biggest” value, you can use:

    SELECT * FROM bestelling 
    WHERE totaalprijs = 
    (
        SELECT max(totaalprijs)
        FROM bestelling
        WHERE totaalprijs < ANY
        (
            SELECT totaalprijs
            FROM bestelling
        )
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to assign a resource I already have a second name, similar to
I want to have a select-only ComboBox that provides a list of items for
I have a second resx file Strings.ps-ps.resx that I want to point my code
I want to have two separate forms on a single create page and one
If all tables I want to delete from have the column gamer_id can i
I want to have the second line (and third, fourth, etc.) of my TextView
I have two tables and I want to have change event on one table.
I want to have a numerical, multidimensional array of scores. The first index is
I have a storyboard(1) that does some basic animations in 2 seconds. I want
I have a List of strings that is regenerated every 5 seconds. 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.