How to Apply Sub Queries on Collection in Magento 2
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.
Categories:
Uncategorized
Tags:
Apply Sub Queries on Collection apply Sub Queries on Collection in Magento 2 Collection Sub Query
View Comments
Comment or Ask a Question
Quick Links