Karl

> I've got two tables one is News items
>
> News_ID    News    etc...
> 1                Today in .....etc
> 2                Hello world .....etc
> 3                Blar di blar....etc
> 4                And now time for something else
> .
> .
> 100            The last thing
>
> and the other is comments on the news items (as well as other things on the
> web site)
>
> Type        Comment_ID        Comment  etc...
> News        1                        What about today then...
> News        1                        This is still today...........
> News        4                        This parot is dead......
> NotNews   4                        Hello..............
>
> What I am trying to get is one SELECT statment that will give me
>
> News_ID        News               Comment_Count  etc...
> 1                   Today in ...       2
> 2                   Hello world.       0
> 3                   Blar di blar        0
> 4                   And now ...etc  1
>
>
> I've tried quite a few SELECTs using LEFT JOIN and HAVING and the best I can
> do is a news list showing only Items that have Comments so the above would
> have returned only NEWS_ID 1 and 4 but not giving 2 and 3 were I want
> 1,2,3,4.....100.
>
> Please help, sorry if this is kids stuff but I'm only just starting with
> MySQL.

=it is fairly straight-forward and you don't need to get into overly complicated joins 
- stick to the simple
Comment_ID = News_ID.

=However, as a beginner I advise you to start with a simple query and then build it up 
- and like many things,
start at the 'far end' and work backwards, eg go for a SELECT of ID and Count first:-

=in the manual, track down the COUNT() function, you might also need to read up on the 
GROUP BY clause of a
SELECT statement.

=now add the WHERE (join) clause and the News column, and the parrot lives again!
=dn



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to