General X++ Development

How do I join two tables in an X++ select statement?

Asked by Sunny Vasty· Aug 13, 2026· 1 answers

How do I join two tables in an X++ select statement?

SSunny Vasty75 reputation · answered Aug 13, 2026

Add the second table with join and put the relationship in the where.

X++
SalesTable salesTable;
CustTable  custTable;

while select salesTable
    join custTable
        where custTable.AccountNum == salesTable.CustAccount
{
    info(strFmt('%1 - %2', salesTable.SalesId, custTable.name()));
}

If the tables can be joined directly, keep it in one query. Running another select inside the loop just creates extra database calls.