Answers.Body: <p>You can see each SQL query that is run for a page by turning <a href="https://craftcms.com/docs/config-settings#devMode" rel="nofollow noreferrer">devMode</a> on and opening your console to read the 'Profiling Summary Report'.</p>
  
  <p>You can see a total query count and each query beings with <code>system.db.CDbCommand.query</code>.</p>
  
  <p>I'd advise maybe isolating the twig code on its own template to avoid having to work out which query was a result of the twig code you're after.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-12T15:11:25.647Z
Answers.Text: You can also try to filter the rows returned to the console to find the right one. In this example using "homepage" as a search term.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-13T10:42:20.850Z
Answers.Text: Yeah this actually what i did, i isolated the twig code but instead of looking at the 'Profiling Summary Report' i used a plugin named `Query log`.The  'Profiling Summary Report' is much easier cause no extra plugin is needed.
Answers.UserDisplayName: nickGR
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-12T14:58:45.673Z
Answers.LastActivityDate: 2017-01-12T14:58:45.673Z
Answers.UserDisplayName: Luke Pearce
Answers.Body: <p>In Craft 3 you can use <code>getRawSql()</code> at the end of the element query. </p>
  
  <pre><code>{% set entries = craft.entries.section('blog').getRawSql() %}
  
  {{ entries }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-10T13:30:50.677Z
Answers.Text: Brilliant - thanks so much! Very useful for debugging twig api templates.
Answers.UserDisplayName: bhu Boue vidya
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-28T21:08:49.587Z
Answers.LastActivityDate: 2018-08-28T21:08:49.587Z
Answers.UserDisplayName: CraftQuest
Body: <p>Is possible to dump a query made on a twig template for a statement like this one for example:</p>
  
  <p><code>craft.entries.section('homepage')</code></p>
  
  <p>Can we some how see the actual SQL query ?</p>
  
Tags: <templating><mysql>
Title: Dump SQL query in Twig template
ThreadText: # Dump SQL query in Twig template
  
  (Asked by: username_0 on 2017-01-12)
  
  Is possible to dump a query made on a twig template for a statement like this one for example:
  
  `craft.entries.section('homepage')`
  
  Can we some how see the actual SQL query ?
  
  **Tags:** templating, mysql
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2017-01-12. Score: 3 | Accepted answer
  
  You can see each SQL query that is run for a page by turning [devMode](https://craftcms.com/docs/config-settings#devMode) on and opening your console to read the 'Profiling Summary Report'.
  
  You can see a total query count and each query beings with `system.db.CDbCommand.query`.
  
  I'd advise maybe isolating the twig code on its own template to avoid having to work out which query was a result of the twig code you're after.
  
  > **Comments:**
  > **username_2**: You can also try to filter the rows returned to the console to find the right one. In this example using "homepage" as a search term.  
  > **username_0**: Yeah this actually what i did, i isolated the twig code but instead of looking at the 'Profiling Summary Report' i used a plugin named `Query log`.The  'Profiling Summary Report' is much easier cause no extra plugin is needed.  
  
  ---
  
  ### Answer by username_3 on 2018-08-28. Score: 6
  
  In Craft 3 you can use `getRawSql()` at the end of the element query.
  
  ```
  {% set entries = craft.entries.section('blog').getRawSql() %}
  
  {{ entries }}
  
  ```
  
  > **Comments:**
  > **username_4**: Brilliant - thanks so much! Very useful for debugging twig api templates.  
  
  ---
  
  