Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 19th, 2004, 12:19 AM
Registered User
 
Join Date: Nov 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to sizemore
Default Aggregate Count also need o

I have 2 tables on a lyric discussion site

[u]Titles</u>
   title_id
   title_name
   title_lyricist
   title_lyrics
   title_artist
   title_entered

And [u]POSTS</u>
   post_id
   title_id
   post_author
   post_text

I want to be able to list all the titles, and count the # of posts for each title. The problem is some titles have zero posts so my query ignores thos titles, butI syill want them returnd where Ill add a ')' for count.

This is the best i could come up with, but still only those that have posts are returned. I still want the titles that don't have a match in the posts table to be returned with a total_count of zero.

Any any help on this ASAP would be much appreciated.


&lt;a href='www.flyingroman.com'&gt;Flying Roman lyric meanings&lt;/a&gt;
 
Old November 19th, 2004, 03:31 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Please post your Query.

Not sure what exactly you are trying to achieve but try this
****
SELECT Titles.title_name, Count(Posts.post_id) AS TotalPosts
FROM Titles LEFT JOIN POSTS ON Titles.title_id = Posts.title_id
GROUP BY Titles.title_name;

****
 
Old November 22nd, 2004, 04:28 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc
Default

You also try it like this

Code:
select A.title_id
     , A.Title_name
     , count(B.title_ID) as Total_Post
 from titles A
left outer
  join posts B
    on A.Title_id = B.Title_ID
group
    by A.TitleID
     , A.Title_name
Jaime E. Maccou
Applications Analyst





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use the SUM Aggregate gregalb SQL Server 2000 1 May 10th, 2007 01:19 AM
DataShaping with Aggregate Jon4Paz Classic ASP Databases 0 September 15th, 2006 01:29 PM
is there any in built function to count page count g.tamilselvan MySQL 1 February 15th, 2006 07:43 AM
Count, sum, count a value, return records CongoGrey Access 1 April 18th, 2005 02:25 PM
Count aggregate function Robert_Hill BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 August 24th, 2004 01:12 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.