Answers.Body: <p>The <code>relations</code> table holds all of the information about relations between Craft elements (entries and categories in your case).</p>
  
  <p>So you would use the <code>sourceId</code> and <code>targetId</code> columns of the <code>relations</code> table and join on the <code>id</code> columns of the <code>entries</code> and <code>categories</code> tables in your example.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-14T04:31:17.237Z
Answers.LastActivityDate: 2020-02-14T04:31:17.237Z
Answers.UserDisplayName: Brad Bell
Body: <p>I have a custom product grid not associated with Craft Commerce. I am wondering, how can I query, in the SQL database, all entries and their related categories? </p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-02-13T19:19:51.757Z
Comments.Text: why would you write an SQL query instead of using craft techniques? (twig / element api)
Comments.UserDisplayName: Clark Nelson
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-02-13T19:53:02.747Z
Comments.Text: Automated reporting purposes.
Comments.UserDisplayName: Akuden 
Tags: <entries><categories><mysql><content>
Title: How to query in MySQL all entries with related categories
ThreadText: # How to query in MySQL all entries with related categories
  
  (Asked by: username_0 on 2020-02-12)
  
  I have a custom product grid not associated with Craft Commerce. I am wondering, how can I query, in the SQL database, all entries and their related categories?
  
  **Tags:** entries, categories, mysql, content
  
  > **Comments:**
  > **username_1**: why would you write an SQL query instead of using craft techniques? (twig / element api)  
  > **username_0**: Automated reporting purposes.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2020-02-14. Score: 1 | Accepted answer
  
  The `relations` table holds all of the information about relations between Craft elements (entries and categories in your case).
  
  So you would use the `sourceId` and `targetId` columns of the `relations` table and join on the `id` columns of the `entries` and `categories` tables in your example.
  
  
  ---
  
  