473,399 Members | 3,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

How do you create a query to give you the count of 2 columns?

I'm having trouble getting the correct count from a total query. I have 2 tables in a 1-To-Many relationship and I want to count a column in the many table. This query works correctly:

Expand|Select|Wrap|Line Numbers
  1. SELECT
  2. tbmAdGroups.AdGroupID,
  3. tbmAdGroups.AdGroupName,
  4. Count(tbmKeyPhrases.KeyPhraseID) AS CountOfKeyPhraseID
  5.  
  6. FROM tbmAdGroups
  7. LEFT JOIN tbmKeyPhrases 
  8. ON tbmAdGroups.AdGroupID = tbmKeyPhrases.AdGroupID
  9.  
  10. WHERE tbmAdGroups.DestinationID=1
  11.  
  12. GROUP BY tbmAdGroups.AdGroupID, tbmAdGroups.AdGroupName;
  13.  
Now I add another table related as another "many" to the same "one" table. I want to count another column on the "many" side. This query doesn't return the correct answer...

Expand|Select|Wrap|Line Numbers
  1. SELECT
  2. tbmAdGroups.AdGroupID,
  3. tbmAdGroups.AdGroupName,
  4. Count(tbmKeyPhrases.KeyPhraseID) AS CountOfKeyPhraseID, Count(tbmSeedPhrases.SeedPhrase) AS CountOfSeedPhrase
  5.  
  6. FROM (tbmAdGroups LEFT JOIN tbmKeyPhrases ON tbmAdGroups.AdGroupID = tbmKeyPhrases.AdGroupID)
  7. RIGHT JOIN tbmSeedPhrases ON tbmAdGroups.AdGroupID = tbmSeedPhrases.AdGroupID
  8.  
  9. WHERE tbmAdGroups.DestinationID=1
  10.  
  11. GROUP BY tbmAdGroups.AdGroupID, tbmAdGroups.AdGroupName;
  12.  
The second query returns counts much greater than they should be. Can anyone see what I'm doing wrong?

Thanks,
Adam
Aug 21 '10 #1
0 839

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Mark | last post by:
Hi, I have a Access database with two tables; a category table and an images table. In the Category table I have a field for Index number and a field for Categories. The images table has a field...
3
by: adam | last post by:
Hello, I have a MySQL table that has (among other fields) an affiliate_id, affiliate_sub_id, and a response_code field. - affiliate_id stores the unique number of each of my affiliates. -...
3
by: Dave Sisk | last post by:
Hi Folks: I'm a little new to SQLServer, so please pardon my ignorance! I've found the INFORMATION_SCHEMA views for TABLES, COLUMNS, and TABLE_CONSTRAINTS. I'm looking for the views that will...
4
by: Stuart E. Wugalter | last post by:
Here is a sample of what I want to do: Table 1 ID FIELD1 FIELD2 1 A T 2 G C 3 T C Table2 ID FIELD1 FIELD2
2
by: mael.iosa | last post by:
Hi, I'm new to this group and fairly new to Access. I have a bunch of data, and after several other queries, I generate the following query which has two fields: Bin, Time 20 3.5 20 3.9 20...
1
newnewbie
by: newnewbie | last post by:
Desperately need help in creating a query to count unique values in a table. I am a Business analyst with limited knowledge of Access….My boss got me ODBC connection to the underlying tables for our...
4
by: m.wanstall | last post by:
I have a crosstab query that compiles data for Months of the year. I have a stacked select query on top of that crosstab query that uses the latest 2 months data and exports it to a fixed length...
7
by: Jim | last post by:
How do I program visual basic to create a "Find Unmatched Query"? I have two tables: - TodaysImport - YesterdaysImport Both tables have the same 6 fields: - User
0
by: afhanna | last post by:
I am using Access to create a result from one table. The table has these columns ID Item Code Sub Item Product Name Size National Price B1 66081 0040 Bread_1 10 $1000...
1
by: Noorain | last post by:
sir i want a query which count total student. here 6 record of student. here one student two times entry. my result is total student 5. i can't do this. my table is: id stu_name dob 1...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.