Talha Bin Shakir
Talha Bin Shakir

Reputation: 2561

SQL Query MAX with SUm

I have a table where i have ID,matchid,point1,point2. I need to get the ID which has the maximum points but the problem i am facing is i need find max record depending on sum of both (point1+point), I have no idea how I can get the max with the combination of 2 columns i have tried query such as,

SELECT MAX(column1+column2) FROM table

MAX(SUM(column1,column2)) FROM table

but nothing works I am using Ms:Access

Upvotes: 1

Views: 2410

Answers (2)

mikej
mikej

Reputation: 66293

You can use a subquery e.g.

select id from table where point1+point2 = (select max(point1+point2) from table)

Note that this will return multiple rows if more than one record has the same maximum points.

Upvotes: 2

Fionnuala
Fionnuala

Reputation: 91376

This will return more than one answer if more than one sum=max:

SELECT ID FROM Table1 
WHERE ([Field1]+[Field2])=(
    SELECT Max([Field1]+[Field2]) AS Expr1
    FROM Table1)

Upvotes: 2

Related Questions