Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A Simple Record Count Question 1

Status
Not open for further replies.

monoone

Programmer
May 24, 2002
219
0
0
US
I know, if it is simple whay are you asking?

Here is my Query:

------------------------------------------
<CFQUERY NAME="GetContacts" DBTYPE="ODBC" DATASOURCE="#request.datasource#">

SELECT ContactType.*, Contact.*

FROM Contact, ContactType

WHERE
ContactType.ContactType = 'Web Sign-Up' AND
Contact.AccountID = #session.AccountID#

</CFQUERY>
---------------------------------------

Here is my output:

---------------------------------------

<CFOUTPUT QUERY="GetContacts">You Have #RecordCount# Subscribers</CFOUTPUT>

----------------------------------------

The problem is that my output is giving me the right number of records but it is reapeating it the 13 times (the amount of records in DB)

Please help.

Thanks,

Eric

 
the 'Web Sign-Up' row from the ContactType table is being joined to every row in the COntact table for that account

this is called a cross join effect

you've omitted your join condition

you probably only want the single contact from that account that is 'Web Sign-Up' type?

rudy
SQL Consulting
 
That is correct - so the SQL is wrong?
 
the SQL is wrong only insofar as it's missing the join condition

how are the two tables related, i.e. by what columns?

rudy
SQL Consulting
 
Code:
<CFOUTPUT QUERY="GetContacts">You Have #RecordCount# Subscribers</CFOUTPUT>

You are asking Coldfusion to repeat for every row returned. Try the following instead:

Code:
<CFOUTPUT>You Have #Getcontacts.RecordCount# Subscribers</CFOUTPUT>

Hope this helps

Wullie

Fresh Look - Quality Coldfusion Hosting

The pessimist complains about the wind. The optimist expects it to change. The leader adjusts the sails. - John Maxwell
 
I am at work - I will try tonight - Than you.

-Eric
 
This still duplicates. Could it be the session???

-Eric
 
Here are the Tables:

---------
Account
----------
AccountID
AccountName
Password
----------


----------
Contact
----------
ContactID
ContactTypeID
AccountID
FirstName
LastName
Email
----------


-------------
ContactType
------------
ContactTypeID
ContactType
AccountID
-------------

Here is the Query:

<CFQUERY NAME="GetContacts" DBTYPE="ODBC" DATASOURCE="#request.datasource#">

SELECT ContactType.*, Contact.*

FROM Contact, ContactType

WHERE
ContactType.ContactType = 'Web Sign-Up' AND
Contact.AccountID = #session.AccountID#

</CFQUERY>
-----------------


Thanks,

Eric
 
I guess I was being lazy. I did a join, the inner join this gave me an error so I did this and it seems to work:

<CFQUERY NAME="GetContacts" DBTYPE="ODBC" DATASOURCE="#request.datasource#">

SELECT ContactType.*,
Contact.*,
Account.*

FROM ContactType,
Contact,
Account

WHERE ContactType.AccountID = Account.AccountID AND
Contact.AccountID = Account.AccountID AND
Account.AccountID = #session.AccountID# AND
ContactType.ContactType = 'Web Sign-Up'

</CFQUERY>

Thanks for the help.

-Eric
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top