0

I need to get the max value on a field of a table but I can't use max or any other aggregation function nor cursors. For example I need to get the max value of the field amount on the table Sales.

4
  • use order by column desc with SELECT top 1 Commented Jul 22, 2019 at 22:22
  • 1
    example : SELECT TOP 1 amount FROM Sales ORDER BY amount DESC Commented Jul 22, 2019 at 22:23
  • Thanks for your answer, but I can't use aggregation nor top functions Commented Jul 22, 2019 at 22:26
  • Please add this constraint to your original question. I take it this is not an actual problem, it's just an experiment or a rhetorical question Commented Jul 22, 2019 at 22:34

1 Answer 1

1

A couple of ways:
1. Sort the column descending and get the 1st row:

select top 1 amount from sales order by amount DESC

2. With NOT EXISTS:

select distinct s.amount 
from sales s 
where not exists (
  select 1 from sales
  where amount > s.amount
)
Sign up to request clarification or add additional context in comments.

1 Comment

It Works, Thanks a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.