How do I get a count of comments by querying the database table? I'm migrating my Drupal forum and trying to export MySQL base as CSV. Among other things, I need to get comment counts.

How can I achieve it?

To be clear, this is what I have up to now:

SELECT node.nid, forum.tid, node_revisions.uid, node_revisions.title, node_revisions.body
FROM node, forum, node_revisions
WHERE node.vid=node_revisions.vid AND node_revisions.vid=forum.vid AND type='forum'


And I also would like to get comment counts for every node.

To be even more clear, this is what I would like to get.


| nid  | taxonomy id | author   | title      |  body       |comments count|
|------|-------------|----------|------------|-------------|--------------|
| 3    | 2           | 1        | Topic 1    | Topic body..|(I need this!)|
| 7    | 3           | 3        | Topic 2    | Topic body..|(I need this!)|
| 2068 | 2           | 287      | Topic 3    | Topic body..|(I need this!)|
| 12738| 4           | 4        | Topic 4    | Topic body..|(I need this!)|


The last column is what I need to get.
I think you can do it using the following query:

SELECT count(comments.cid), node.nid
FROM node
INNER JOIN comments on node.nid = comments.nid
WHERE node.type='forum'
GROUP BY node.nid