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!

Difference between Max, First and Top 1

Status
Not open for further replies.

KimmieB

Programmer
Apr 1, 2005
20
US
I'm trying to get the latest date in a query using 2 tables with a left join. Can someone explain the difference about when to use the Max function vs. the First or Top 1 when sorting by descending order?
 
MAX gives you the largest value (numeric) or the latest value (dates) or the one furthest down the alphabet (text values) for a field. It does not depend on the ordering of the records but it does depend on their filtering and grouping.

FIRST gives you the first value retrieved (after sorting by Order By) for a field. It may or may not be the MIN or MAX value. It does depends on the ordering, filtering and grouping.


TOP 1 gives you the first record after the resultant recordset is ordered. It is a record selector, not a specific field selector. It does depends on the ordering, filtering but not the grouping of records.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top