SQL selects maximum value from table

At one of my interviews I was asked how to select the maximum value from the database without the keyword MAXand TOP.

My answer was:

select Table.Value 
from Table 
where Table.Value >= all( select Table.Value from Table) 

But that was wrong. The interviewer said that I have to do this with only one choice.

Any ideas?

Thank;)

+3
source share
5 answers

What about:

select -min(-fld) from table


The less efficient and ugly Woops missed the only restriction of choice

select distinct Value from Table T
  where not exists (select Value from Table where Value > T.Value)
+6
source
SELECT t1.Value
FROM atable t1
 LEFT JOIN atable t2 ON t1.Value < t2.Value
WHERE t2.ID IS NULL
+4
source

( MySQL, ):

SELECT table.value FROM table ORDER BY table.value DESC LIMIT 1;
+2
SET ROWCOUNT 1

SELECT number 
FROM master..spt_values
ORDER BY number DESC
+2

, , . max.

, .

0

All Articles