2

Hello i create custom module with database i want to show data with filter by somw columns i want to convert below query OR Can you tell what we do for it How to use getSelect()->where() in magento2? ex:-

select * from table where hello_status=1 AND ( location='blabla' OR location='bla')
AND (DATE<='' AND DATE IS NUll )
0

1 Answer 1

5

The Magento 2 SQL query syntax remains the same as in Magento 1.x (because they both use the same Zend Framework database library).

For example:

$connection = $this->getConnection();
$select = $connection->select()
    ->from(
        ['o' => $this->getTable('sales_order_item')],
        ['o.product_type', new \Zend_Db_Expr('COUNT(*)')]
    )
    ->where('o.order_id=?', $orderId)
    ->where('o.product_id IS NOT NULL')
    ->group('o.product_type');

https://github.com/magento/magento2/blob/2.0.0/app/code/Magento/Sales/Model/ResourceModel/Order.php#L93-L101

2
  • How to call module function in block / template file.
    – Vishal
    Dec 3, 2015 at 4:47
  • Fatal error: Call to undefined method Namespace\Module\Model\ResourceModel\Notification\Collection::select() error
    – Vishal
    Dec 3, 2015 at 5:25

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