Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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

share|improve this question

2 Answers 2

up vote 9 down vote accepted

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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