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 )
Vishal
  • 773
  • 2
  • 8
  • 18

1 Answers1

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

Rasclatt
  • 125
  • 7
Dmitrii Fediuk
  • 4,899
  • 2
  • 23
  • 19