How to get the SQL expression for a collection?

Get the corresponding \Magento\Framework\DB\Select instance with the getSelect() method, and then follow the instriction How to get the SQL expression for a \Magento\Framework\DB\Select or \Zend_Db_Select, for example:

$collection->getSelect()->assemble();

You can also use the printLogQuery() method to print or log the SQL query:

1 Like

See also: