query to count match filed

User avatar
sal21
PlatinumLounger
Posts: 4343
Joined: 26 Apr 2010, 17:36

query to count match filed

Post by sal21 »

in the same dabtabase access have 2 table:
table1
table2

table1 have:

field1 (cod of agengy) filed2 (account number of empolye)
4500 AAAA
4500 BBBB
4500 BBBB
5400 CCCC
5400 CCCC

table2 (list of emploied indefied from the account number):

field1
AAAA
BBBB
DDDD
CCCC

i need a query to count the numbers of "badged" for each employes in agengy

in this case the empolie AAAA have "badged" 1 time in agengy 4500, empolie BBBBB have "badged" 2 time in agengy 4500, empolie CCCCC have "badged" 2 time in agengy 5400

4500 =1 for AAAA
4500 =2 for BBBB
5400 =2 for CCCC
Last edited by sal21 on 03 Mar 2012, 11:51, edited 2 times in total.

User avatar
HansV
Administrator
Posts: 78393
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: query to count match filed

Post by HansV »

What does table2 have to do with this? As far as I can tell, you're merely performing a count in table1:

SELECT field1, filed2, Count(*) AS Conta FROM table1 GROUP BY field1, filed2
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4343
Joined: 26 Apr 2010, 17:36

Re: query to count match filed

Post by sal21 »

HansV wrote:What does table2 have to do with this? As far as I can tell, you're merely performing a count in table1:

SELECT field1, filed2, Count(*) AS Conta FROM table1 GROUP BY field1, filed2

sorry me Hans changed my request... the table in question are two :grin:

User avatar
HansV
Administrator
Posts: 78393
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: query to count match filed

Post by HansV »

In your example, the SQL that I posted will return the required result. Are there values of filed2 in table1 that do not occur in field1 in table2? And should such values be omitted from the query result?
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4343
Joined: 26 Apr 2010, 17:36

Re: query to count match filed

Post by sal21 »

HansV wrote:In your example, the SQL that I posted will return the required result. Are there values of filed2 in table1 that do not occur in field1 in table2? And should such values be omitted from the query result?
mofified my original post. :sad: :scratch:

User avatar
HansV
Administrator
Posts: 78393
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: query to count match filed

Post by HansV »

You haven't answered the question in my previous reply. It's still not clear what role table2 plays.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4343
Joined: 26 Apr 2010, 17:36

Re: query to count match filed

Post by sal21 »

HansV wrote:You haven't answered the question in my previous reply. It's still not clear what role table2 plays.
table2 is the list of serial account of single emploies

User avatar
HansV
Administrator
Posts: 78393
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: query to count match filed

Post by HansV »

Have you actually tried the SQL from my first reply?
Did it do what you want?
If not, what was wrong?
Best wishes,
Hans