Jump to content

[SOLVED] Query help


CroNiX

Recommended Posts

I need some help with a query that I haven't done before and have not yet succeeded.

 

I have 2 tables.

 

blog          blog_comments
-----          ------------
id              id
entry         blog_id
...              visible

I am trying to:

1) select everything from blog

2) count comments left for each blog.entry

3) count comments left for each blog.entry where visible = 0

I got 1 and 2 accomplished using the following statement and need help getting #3.

SELECT
    blog.id,
    blog.entry,
    Count(blog_comments.id) AS comment_total,
FROM
    blog
    Left Join blog_comments ON blog.id = blog_comments.blog_id
GROUP BY
    blog.id,
    blog.entry
ORDER BY
    blog.`date` DESC

Obviously the tables have a lot more fields, but this is the needed info to accomplish what I am after.  If anybody could help I would appreciate it.  Temporarily I am running 2 querries to get the data I need for #3 but would like to just have 1 statement and would like to learn this.

 

Thanks for any insight!

Link to comment
Share on other sites

hum...is visible either 1 or 0...what about this:

SELECT
    blog.id,
    blog.entry,
    Count(blog_comments.id) AS comment_total,
    COUNT(blog_comments.visible) - SUM(blog_comments.visible) AS nonvisible_total
FROM
    blog
    Left Join blog_comments ON blog.id = blog_comments.blog_id
GROUP BY
    blog.id,
    blog.entry
ORDER BY
    blog.`date` DESC

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.