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 write a SQL Safe Query using quoteInto() method magento 2?

Using a SQL quoteInto() method, Write a Query using Magento standard way with SQL Safe quoted value.

You can avoid SQL injection attacks, no matter which database you use, is to separating the data value from the SQL statement. You can use ? to pass data in SQL query with the quoteInto() method.

Return Type: Always returns a string with SQL-safe quoted value placed into the original text.

You can use a given method in the direct SQL query for a safe quote with SQL conditions. Continue reading “How to write a SQL Safe Query using quoteInto() method magento 2?”

Write a fetchCol() Sql query in Magento 2.

Write a Mysql fetchCol() query using Magento standard way without using the Model file.

To Fetches the first column of all SQL result rows as an array.

Return Type: fetchCol() always returns as an array. Continue reading “Write a fetchCol() Sql query in Magento 2.”