in reply to Counting rows from table1 while querying table2

Your question is very vague, but maybe you want something like that:

SELECT COUNT(c.id) FROM categories c, posts p WHERE c.id = p.catid

In Englisch that's "Count the catgeories for which a corresponding post exists" - if that's not what you want you have to clarify your question.