Menu Close
    Hire Us Request Quote Reading List Switch to Dark Mode

    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.

    . . .

    Comment

    Add Your Comment

    Be the first to comment.

    Back to Top
    css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again
    Close