5

How do you view the query that a 'View' is using to gather data from the database?

16

Go to admin/structure/views/settings, check Show information and statistics about the view during live preview and then Show the SQL query checkbox that will appear below.

2

If you want to see a preview of the query being used when viewing the view as opposed to editing it you can use hook_views_pre_execute():

function MYMODULE_views_pre_execute(&$view) {
  dpq($view->build_info['query']);
}

The dpq() function is provided by the devel module so you will need to have that installed for this to work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.