How to use Group By and Having Clause SQL query in magento 2?

Magento Group By SQL query used to fetch the same set of values from a specified column. While We use group by clause with aggregate function

We must have to use the Having clause and where clause is not used with Group By Aggregrate functions. Continue reading “How to use Group By and Having Clause SQL query in magento 2?”

How to use left join SQL query in Model class Magento 2?

Magento 2 Left Join SQL query in resource model class to get data from multiple tables.

Left Join is used to fetch all records from the left table and retrieve matching records from the second table.

We can use the joinLeft() method to use Left Join in Magento Collection.

A Demo to fetch customers with customer address details like city and postcode from the customer_address_entity table using the join query. Continue reading “How to use left join SQL query in Model class Magento 2?”

How to get entity type link field value in Magento 2 Commerce?

In Magento commerce, Retrieve the value of the link field for the specific entity type programmatically to join the database query.

Magento uses $metadata->getLinkField() to get the name of the field for the given entity type using MetadataPool class.

You need to pass the entity type interface to fetch the link field name. When you working with Magento commerce, you required entity link field value instead of table primary key entity_id to join query with other database tables. Continue reading “How to get entity type link field value in Magento 2 Commerce?”