MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii I have a query as follows: SELECT date(c.timestart) as ondate, c.userid, u.username, count(c.callinfoid) as numCalls, sum(b.broquant) as numBroc, sum(b.broquant)/count(c.callinfoid) as BrochuresaCall FROM callinfo c, user_ u, brochurerequest b WHERE c.userid = u.userid AND b.callinfoid = c.callinfoid GROUP BY c.userid,u.username,ondate; But, I want numCalls to count rows where b.callinfoid is not in c.callinfoid. How do i do it ? I am on version 7.0.2. Below are the table create statements that I have. ------------------------------------------------------------------------- CREATE TABLE Patient ( patientId INT8, personId INT8 , constraint Patient_key primary key (patientId) ); CREATE TABLE User_ ( userId INT8, userName TEXT constraint uname_uniq unique, userPassword TEXT, userRole INTEGER, userMode TEXT, personId INT8, constraint User_key primary key (userId) ); CREATE TABLE CallInfo ( callInfoId INT8, timeStart TIMESTAMP, timeStop TIMESTAMP, marketing TEXT, userId INT8 constraint CI_U_FK references User_, patientId INT8, constraint CallInfo_key primary key (callinfoId) ); CREATE TABLE BrochureRequest ( broQuant INTEGER, method TEXT, comment TEXT, officeId INT8, callInfoId INT8 constraint BR_CI_FK references CallInfo ); __________________________________________________ Do You Yahoo!? Yahoo! Auctions - buy the things you want at great prices http://auctions.yahoo.com/ ---------------------------(end of broadcast)--------------------------- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/users-lounge/docs/faq.html