database – Need help for creating nodes but only if they not exist

I have Company data in external database. The first column of the data contains the id of different companys.
I will create nodes for every company but only if they do not exist identified by the id in the first column.

// Get Data from external DATABASE
  db_set_active('db_wirdfit');
  $result_wirdfit = db_query('SELECT * FROM wirdfit.wirdfit_data');
  db_set_active();
  $result_drupal = db_query('SELECT * From drupal.field_data_field_id');
  $wirdfit_id = array();
  $drupal_id = array();

 foreach ($result_wirdfit as $row) {
  $wirdfit_id= $row->id;

  $node = (object) array();
  $node->language = LANGUAGE_NONE;
  $node->type = 'page';
  $node->title = $row->id;
  node_object_prepare($node);  //Set some default values

   foreach ($result_drupal as $row1) {
   $drupal_id = $row1->field_id_value;
  
if ($wirdfit_id != $drupal_id){
  $node->is_new =TRUE;
  node_save($node);
 }
}

There is a failure in the loop i think i missed some conditions and don´t get it. It creates a node that is already available.

Thanks