How to set current time for timestamp and datetime type in magento object save repository?

Timestamp and DateTime type of MySQL is used to set date and date/time value to the database table.

Both types contain the default attribute called default=”CURRENT_TIMESTAMP” to use the set current time in the table.

While you are working with the db_schema.xml file and need to add/update the current time in the table for any specific object save repository, you can set the default attribute with the value CURRENT_TIMESTAMP to save current time while placing an entry in the database table. Continue reading “How to set current time for timestamp and datetime type in magento object save repository?”

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 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?”