I am trying to perform an SQL query kind of thing where I need to check if my database table contains a particular record or not. If it does, do nothing else add the record which isn't present. My table sample contains fields like sample_id (auto-incremented), order_id, order_email_id, review_request, coupon_sent . It has got 4 records having order_ids (71, 74, 126, 165) To obtain $ids, I have this query, $to_date = date('Y-m-d H:i:s',strtotime('-3 days')); $orders = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('status', 'complete')->addFieldToFilter('updated_at',array('to' => $to_date ))->addAttributeToSelect('customer_email')->addAttributeToSelect('entity_id'); foreach($orders as $order) { $email = $order->getCustomerEmail(); $id = $order->getEntityId(); $sample = Mage::getModel('sample/sample')->getCollection()->addFieldToFilter('orde...