sql: trying to select the second biggest element but selects the biggest

Posted by matthy on Stack Overflow See other posts from Stack Overflow or by matthy
Published on 2010-04-08T14:10:56Z Indexed on 2010/04/08 14:13 UTC
Read the original article Hit count: 320

Filed under:
|
|
|

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

© Stack Overflow or respective owner

Related posts about sql

Related posts about query