Write a fetchPair mysql query in Magento 2.

Write a Mysql fetchPair() query using Magento standard way for Fetches all SQL result rows as an array of key-value pairs.

You can write direct SQL query fetchPair() without worrying about Model operation using below code snippet.

Return Type: fetchPair() always return as an array with key-value pair as output.

Base Definition of function:

Let’s we are writing a query from sales_order table to accomplish fetchPair() query operation.

Output:
Here in output, you can see key value is entity_id and value as the status of the order.

Check for other Direct SQL Query in Magento 2