There are some views in my site. I have configure the setting to fetch the Views query. I want to convert those query to MySQL query to run & getting the result directly.
How can I do this?
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.Sign up to join this community
Try the Views Show Query module
This module shows real SQL query in Views UI during live preview.
'Real query' means it is rewritten by query_alter hooks. For instance, node access checks are added, so this requires selecting the user on behalf of which the query is supposed to be executed. So the module adds 'User ID to show final query' field in views preview form. You must enter numeric user ID in this field to view the real SQL query.
This module makes it possible to show SQL query not only during live preview, but when the view is executed normally. You can add footer to the view with the following PHP code:
<?php $rows = array(); $view->exposed_input['views_show_query_uid'] = 1; views_show_query_views_preview_info_alter($rows, $view); drupal_set_message($rows['query']); ?>
There another module called Query Coder which Convert SQL query to Drupal Database abstraction layer code.
Also worth mentioning, just in case you didn't know, Views will show you the SQL that it generates and uses if you turn on its visibility in the views settings page
However, this is query can be seriously complex if you have lots of relationships and contextual filters. The other modules recommended by @KrishnaMohan make it a lot more digestible. But it is something that it does natively.