Simple AX query returns different values than simple SQL call...why?

Why would these both return different results? It’s a one company environment. Try on your system. The purpose is to get the number of orphaned DirPartyTable records.

static void Job14(Args _args)

{

DirPartyTable dirPartyTable;

CustTable custTable;

VendTable vendTable;

;

select count(partyId) from dirPartyTable

where dirPartyTable.Type == DirPartyType::Organization &&

dirPartyTable.dataAreaId == ‘ABC’

notexists join custTable

where custTable.PartyId == dirPartyTable.PartyId &&

dirPartyTable.dataAreaId == ‘ABC’

notexists join vendTable

where vendTable.PartyId == dirPartyTable.PartyId &&

dirPartyTable.dataAreaId == ‘ABC’;

info(strfmt("%1", dirPartyTable.PartyId));

/*

– SQL call with different values

SELECT DT.[NAME],

DT.[PARTYID] as ‘DirPartyTable.PartyId’

FROM [AX_Dev].[dbo].[DIRPARTYTABLE] DT

where not exists (select ACCOUNTNUM FROM [AX_DEV].[dbo].[CUSTTABLE] CT where DT.PARTYID = CT.PARTYID) AND

not exists (select ACCOUNTNUM FROM [AX_DEV].[dbo].VENDTABLE VT where DT.PARTYID = VT.PARTYID)

and DT.TYPE = 2

and DT.DATAAREAID = ‘ABC’

*/

}