Here is an example of using an SQL query in the query module to show only the categories associated with an entry that have other entries associated with them. The user will see the phrase “Read more about category” only when there is something to see—otherwise the category name will not be displayed:
<div class="categories">
<p>
{exp:query sql="SELECT cp.entry_id,
cp.cat_id AS cat_id,
cats.cat_name,
cp2.cat_id,
cp2.entry_id
FROM exp_category_posts AS cp
JOIN exp_categories AS cats
USING ( cat_id )
JOIN exp_category_posts AS cp2
USING ( cat_id )
WHERE cp.entry_id = '{entry_id}'
AND cp2.entry_id <> '{entry_id}'
GROUP BY cp.cat_id"}
Read more about <a href="{path=weblog/index}category/{cat_name}">{cat_name}</a>.
{/exp:query}
</p>
</div> <!-- categories -->
Disclaimer: this code is based on the assumption you will be using it with a weblog/index template. Change as needed to fit your needs.
Category:Queries Category:Tips
