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

2 Answers 2


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.


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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