Quantcast
Channel: Webkul Blog
Viewing all articles
Browse latest Browse all 5537

How to Apply Sub Queries on Collection in Magento 2

$
0
0

How to apply Sub Queries on Collection in Magento 2:

In this blog we will see how we can apply sub queries on collection in magento 2.

A sub query is used to return data that will be used in the main query as a condition to further restrict the data to be retrieved.

$collection->getSelect()
     ->columns([
         'first_selected_column_name' => new \Zend_Db_Expr(
             'select column_name From table_name  where condition'
         ),
         'second_selected_column_name' => new \Zend_Db_Expr(
             'select column_name From table_name  where condition'
         )
     ]);

In this way we can apply nested or sub queries on collection. Hope it will be helpful for you. 🙂

For any query comment below.


Viewing all articles
Browse latest Browse all 5537

Trending Articles