How to display SQL query in Views module

How to display SQL query in Views module

When you build a drupal website, the views module is your great friend. It will help you build lists of content (eg. the 5 latest blog posts). Sometimes though you would love to learn what query is the view running exactly. This may be for debugging or a different reason. Here is how to get it in code.

Below you have instruction how to display full SQL query in Views module in Drupal.

  • Download and enable Devel module
  • Open file views/plugins/views_plugin_query_default.inc
  • In class views_plugin_query_default find method query($get_count = FALSE)
  • In method query() before return add line: dpq($query);

Example code:

Drupal views query SQL

 

How it looks on website:

Drupal views query SQL