How to use insertFromSelect query in database Magento 2 with best practice?

You can use INSERT IGNORE INTO mysql query with the help of insertFromSelect() method in Magento 2 with use of magento best standard in your module.

Lets we have a query that use the insertFromSelect method to run a query.

Raw SQL Query to add an entry to the small_image attribute from the image attribute value. Continue reading “How to use insertFromSelect query in database Magento 2 with best practice?”

How to check is database table exists or not by Magento 2?

You can verify the given database table available in the database with the help of isTableExists() method by use of Magento\Framework\App\ResourceConnection class.

This method is useful when you are dealing with a database query and want to run your query on the safe side to check whether the first given table exists or not before firing the SQL query. Continue reading “How to check is database table exists or not by Magento 2?”

How to use SQL distinct Query in Magento 2?

Magento 2 distinct SQL Query is used to return results as unique records for the given field by skipping duplicate values from the SQL Response.

If a Specific Column in a table contains, multiple duplicate values and you want to skip it and fetch only single records for the same column, You can use distinct keywords in a query to filter out duplicate values.

You can Learn about, A List of Direct SQL Queries in Magento 2.

Just use distinct keywords on a query like, $connection->select()->distinct()

Continue reading “How to use SQL distinct Query in Magento 2?”