I have two table named A and B in both table 6 and 10 records are inserted respectively, in both table one field is common. How can we compare the records f both table using that common field and found that records which are not in the table A.

abhisingh
Kilo Contributor

I have two table named   A and B in both table 6 and 10 records are inserted respectively, in both table one field is common. How can we compare the records of both table using that common field and found that records which are not in the table A.

10 REPLIES 10

Hi Abhiram,



Use a Join query and you only need to create two GlideRecord calls instead of 10 (or however many records are in table2)...




-Brian


what i am looking for is-- in table A where 6 records entered, it's 1 record is not available in table B(where 10 records entered), so i want to find out that one record which is in Table A but not in Table B.


Gurpreet07
Mega Sage

abhisingh
Kilo Contributor

what i am looking for is-- in table A where 6 records entered, it's 1 record is not available in table B(where 10 records entered), so i want to find out that one record which is in Table A but not in Table B.


Hi Abhi,



For that scenario, and using the script from earlier:



var grMatch = new GlideRecord('A');


grMatch.addJoinQuery('B', 'tableAfield', 'tableBfield');


grMatch.query();


var matchesFound = [];


while(grMatch.next()){


      matchesFound.push(grMatch.tableAfield.toString());


}



var grNoMatch = new GlideRecord('A');


grNoMatch.addEncodedQuery('tableAfieldNOT IN' + matchesFound.join());


grNoMatch.query();


while(grNoMatch.next()){


        //do something with the records, (e.g.)


        gs.print(grNoMatch.getDisplayValue());


}





-Brian