I have looked through the documentation for ee https://ellislab.com/expressionengine/user-guide/add-ons/query/

There is no mention of exp:query sql select for a relationship field. I need some help with the syntax.

I am looking to get a total_results value from a select by channel and value in multi select relationship field.

Any help would be awesome. I am very new to the exp:query mod.

1 Answer 1


If you really need to use the Query module for this then this should do the trick to get all the related entries (children) of a given entry:

{exp:query sql="SELECT count(*) as total FROM exp_relationships
WHERE parent_id = {entry_id}"}

This example assumes you are inside a channel:entries loop where the {entry_id} variable can be passed to the WHERE parent_id clause. You may need to tweak the WHERE clause to better suit what you are looking for.

I'm not entirely sure what data you're after, so it's hard to say. But you may want to consider instead just using :total_results on your relationship custom field tag.


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.