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?

  • why would you write an SQL query instead of using craft techniques? (twig / element api) Feb 13, 2020 at 19:19
  • Automated reporting purposes.
    – Akuden
    Feb 13, 2020 at 19:53

1 Answer 1


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.

Your Answer

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

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