Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with max

Status
Not open for further replies.

zeert2002

Programmer
Sep 26, 2007
13
US
Hi I need help with the max function.
How do I get the max of the queries result in sql?


my query is:
select val from table where id in(3,4);

It will give me two values. From this what should I add so that it will give me only 1 value and that value is the max of the two? Thanks.
 
Well,
Code:
SELECT MAX(val)
FROM my_table
WHERE id IN (3,4)
GROUP BY id;
will give you the maximum value for each ID.
To narrow this down to the greatest of either of them, you could simply use
Code:
SELECT MAX(val)
FROM my_table
WHERE id IN (3,4);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top