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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

counting records dependant on a second table

Status
Not open for further replies.

raysql

Programmer
Mar 27, 2003
3
GB
Hi,

I have 2 tables. One called "essays" the other called "sales_details". "sales_details" contains a column called "Essay_ID" with numerical values which can be repeated. The full list of numerical values are in the other table "essays" in the column "essayID".

I need to count the amount of times a certain value in "Essay_ID" appears? However the COUNT column that the query produces needs to list all the values from the table "essays" with the corresponding COUNT value next to it or zero if there is no value!

Basically the ASP page output should be 2 columns.... the first being the full list from table "essays" of the column "essayID" and the second column being the COUNT column?

Can anyone please help

Kind regards

Ray
 
SELECT essays.essayID, Count(sales_details.Essay_ID) AS TotalID
FROM sales_details RIGHT JOIN essays ON sales_details.Essay_ID = essays.essayID
GROUP BY essays.essayID;

Trisha
padinka@yahoo.com
 
Sorry but can you provide more details please? .. are you talking about data dictionary.. if so sorry i dont understand the concept??
 
Wow. That was a long time ago. You just need to do an outer join on your query. In the example I gave, a RIGHT JOIN. Copy and paste the query into your database and run it. It should give you a sample query. I used the table names and the field names that you gave me. I didn't Count the 'certain field' you mentioned because you didnt give me the field name so I counted the Essay_ID.

Trisha
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top