2

I have two tables in the magento one is notification and once is notification_customer i have to take the items from the notification table if there is no entry for that user and notification item in the notification customer table.

Table structure of notification table

nid name ....

Table structure of notification_customer table

nrid nid cid

2 Answers 2

2

Try this

 $subcollection = Mage::getModel("notifications/notificationcustomer")->getCollection()
            ->addFieldToSelect('nid')
            ->addFieldToFilter('cid',$needle1);
        $collection1 = Mage::getModel("notifications/notification")->getCollection();
        $collection1->getSelect()->where("nid not in (".$subcollection->getSelect()->__toString().")");
1
  • I will check and let you know. Thank you for the immediate response Jan 4, 2017 at 9:48
2

You can use this example as reference for making nested select statement in magento

$orderTable = Mage::getResourceModel('sales/order_collection')
            ->addFieldToFilter('created_at', array('gt' => $date));
        $this->getSelect()
            ->joinLeft(array('order_table' => new Zend_Db_Expr( '(' . $orderTable->getSelect() . ')')),
    'e.entity_id = order_table.customer_id')
            ->where('order_table.entity_id', 'notnull');
        return $this;
    }
    $this->getSelect()
        ->joinLeft
        (
            array('recommendationsyestable' => new Zend_Db_Expr( '(SELECT COUNT(*) as recommendationsyes, recy.review_id as rec_review_idy FROM ar_review_recommendations AS recy WHERE recy.status_id=2
    AND recy.vote=2)')),
            'recommendationsyestable.rec_review_idy = rt.review_id'
        )
        ->joinLeft
        (
            array('recommendationsnotable' => new Zend_Db_Expr( '(SELECT COUNT(*)
     as recommendationsno, recn.review_id as rec_review_idn FROM ar_review_recommendations
    AS recn WHERE recn.status_id=2 AND
    recn.vote=1)')),
            'recommendationsnotable.rec_review_idn = rt.review_id'
        );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.