Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 12 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) {

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


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.