web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Is maxOf(RecId) same as sort by order recId desc?

(0) ShareShare
ReportReport
Posted on by 1,965

If I select first only order by recId desc...is it the same as select maxOf(RecId)

Or could the maxOf result in wrong result..I mean is order by recId desc more reliable?

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    It fetches the same value. Just note that you should use a field list if your don't use maxOf(), otherwise you would be fetching all fields instead of just RecId.

    select firstOnly RecId from myTable
        order by RecId desc;

    Because using maxOf() is shorter and it makes your intent more obvious, you should prefer it in this case.

  • .. Profile Picture
    1,965 on at

    Hi Martin,

    Do u know why after using maxOf(RecId)

    I can't access locator of DirPartyContactV3Entity..the recId is null as well

    IMG_5F00_20220221_5F00_133111.jpg

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    Yes, I know.

    The only fields that will have a value are those that you either aggregate (RecId) or group by (Type and IsMobilePhone). No other fields has a value defined.

  • .. Profile Picture
    1,965 on at

    Hi Martin,

    But I can't group by locator because the logic won't work in that case.

    What I did is that I made  a view  with max electronic address RecId and group By Type,IsMobile and PartyNumber. The view contains (logistics electronic address, logistics location,dirPartyLocation and dirPartyTable) then in code I did a join of the view with logistics electronic address based on recId. Could I have done it without the view and by code? I mean can I edit the above code to make it work

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    I'm sorry, but I can't tell what code you should use instead of your code if all I know is the code. I don't know what you're trying to achieve. Most importantly, it's not clear why you're selecting the highest RecId.

    If you want to keep the query as it is, then we there is no way how to edit your code to give you the extra field. It would require doing things differently.

    Anyway, that's not related to the topic of this thread (Is maxOf(RecId) same as sort by order recId desc?). If you want to discuss this other topic, please create a new thread. And if you agree that "Is maxOf(RecId) same as sort by order recId desc?"has been answered, please verify the answer.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 549 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans