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

Announcements

News and Announcements icon
Community site session details

Community site session details

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

select first only and select query in x++

(2) ShareShare
ReportReport
Posted on by 698

Hi team,

I have a query. Is both “select first only” and “select” query is return the first record only without where condition?

1.

CustTable custTable;

select firstOnly custTable;

if (custTable)
{
   info(strFmt("Account number: %1", custTable.AccountNum));
}

 

2.

select custTable;

if (custTable)
{
   info(strFmt("Account number: %1", custTable.Accountnum));
}

Note- I don't have system access so unable to check it.

Pls advise, thanks 

 

Categories:
I have the same question (0)
  • Verified answer
    Subra Profile Picture
    1,934 Super User 2026 Season 2 on at

    Hi @CU10121822-0 

    When you use select firstonly keyword in your select query it will optimize the SQL query in the backend like it will look only for Top (1) record. If we doesn't use the keyword the query is not optimized.

    Thanks,
    Subra

  • CU10121822-0 Profile Picture
    698 on at

    Hi Subra, based on my above examples pls explain what it will return .

    thanks

  • Verified answer
    André Arnaud de Calavon Profile Picture
    306,587 Super User 2026 Season 2 on at

    Hi,

    In your first statement, the SQL server will return only one record as Subra mentioned. It will be translated to return top 1.

    The second statement is bad coding. This will return all records from the CustTable. The focus will be on the first record. The issue here is related to performance. Returning one record is way faster than returning a set of all records.

    Your examples will have the same result, but the difference is performance.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 305 Super User 2026 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 281 Most Valuable Professional

#3
Anton Venter Profile Picture

Anton Venter 266 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans