473,387 Members | 1,779 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,387 software developers and data experts.

Count different 2 field in 1 table at Access Query

yosiro
34
I have 2 table, below:

Tabel1
-------------------
ID C1 C2
-------------------
1 QQ QB
2 QB QC
3 QC QB
4 QC QQ
5 QC QQ
6 QC QB
7 QQ QC
8 QC QQ
9 QC QB
10 QQ QB

Tabel2
----------
ID A1
----------
1 QQ
2 QB
3 QC


So i want to create a query like this:

A1 Total
QQ 6
QB 6
QC 8

Please help me, i use MS access 2013, thanks
Mar 1 '16 #1

✓ answered by jforbes

You are not very clear with your question, so this is just a guess at what you are looking for:
Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2.    A1
  3. , (SELECT COUNT(C1) FROM Table1 WHERE Table2.A1=Table1.C1 OR Table2.A1=Table1.C2) AS Total 
  4. FROM Table2

5 1170
jforbes
1,107 Expert 1GB
You are not very clear with your question, so this is just a guess at what you are looking for:
Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2.    A1
  3. , (SELECT COUNT(C1) FROM Table1 WHERE Table2.A1=Table1.C1 OR Table2.A1=Table1.C2) AS Total 
  4. FROM Table2
Mar 1 '16 #2
NeoPa
32,556 Expert Mod 16PB
Let's start by asking the question properly, shall we? Your job really, but I'm guessing you don't speak English natively so this might be easier for me than it is you. You just need to say if I get it wrong.

So, you would like a query that counts how many of each value are found in either column of Table1. I would guess Table2 is irrelevant and is only there because you hadn't realised that yet.

The way I would do that is to create a sub-query for each column (field) and UNION the results together.

Something like :
Expand|Select|Wrap|Line Numbers
  1. SELECT   [CField]
  2.        , Sum([CountC]) AS [TotC]
  3. FROM     (SELECT   [C1] AS [CField]
  4.                  , Count(*) AS [CountC]
  5.           FROM     [Table1]
  6.           GROUP BY [C1]
  7.           UNION ALL
  8.           SELECT   [C2] AS [CField]
  9.                  , Count(*) AS [CountC]
  10.           FROM     [Table1]
  11.           GROUP BY [C2])
  12. GROUP BY [CField]
  13. ORDER BY [CField]
Mar 2 '16 #3
NeoPa
32,556 Expert Mod 16PB
Now, depending on whether or not it's possible to have Table1 records with the same value in both C1 & C2, JForbes' suggestion will either work or it won't. If it isn't possible then his will work, but will need both tables. Hardly a problem I would expect. If it is possible, of course, then his suggestion won't be accurate.

I would recommend changing the Count() parameter to *, but that's just for safety. In most scenarios it'll work fine just as it is.
Mar 2 '16 #4
yosiro
34
Am sory to make confuse coz my bad english, am from indonesia.
I want to revision about table 1. here's the image:



And this is the file : https://www.dropbox.com/s/mzszyt120i...se1.accdb?dl=0

So i want to create query that can count total of each Group of Table 2 in Table 1. I hope you are get it what i mean.
Mar 2 '16 #5
yosiro
34
I change the code from jForbes to my latest post, thanks man its work

Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2.    A1
  3. , (SELECT COUNT(C1) FROM Table1 WHERE Table2.ID=Table1.C1 OR Table2.ID=Table1.C2) AS Total 
  4. FROM Table2
Mar 3 '16 #6

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

Similar topics

11
by: Wolfgang Kaml | last post by:
Hello All, I have been working on this for almost a week now and I haven't anything up my sleeves anymore that I could test in addition or change.... Since I am not sure, if this is a Windows...
5
by: anthonyberet | last post by:
I work for an organisation that uses a bespoke document imaging system, the database of which is an MS sql server. We have MS Access and already use it for some querying of the database. The...
4
by: hi | last post by:
I'm having major problem with multiplications in querys. E.g. Table 1 f1 Single f2 Single f1=1.12 f2=.2345 I create a query with just one field a:f1*f2 and I get
5
by: redstamp | last post by:
Try as I might I cannot find a way to write an access query to return a result set with the records from my database WITHOUT a certain set of values within a field. To explain, I have a table of...
1
by: TB | last post by:
Hi there all, How do i count , using a query, the number of records in a certain table, where one of the fields has a null value, in other words only the records where the field has a null...
1
by: Haole88 | last post by:
Here's what I have: Form 1 - has a field "Initial Man Hours" that I type a # of minutes into when I first talk to a client subForm 2 (in Form 1)- is a continuous form that has a field "Add'l...
1
by: CoolFactor | last post by:
MY CODE IS NEAR THE BOTTOM I want to export this Access query into Excel using a command button on an Access form in the following way I describe below. Below you will find the simple query I am...
6
by: jsacrey | last post by:
Hey everybody, got a secnario for ya that I need a bit of help with. Access 97 using linked tables from an SQL Server 2000 machine. I've created a simple query using two tables joined by one...
5
by: billelev | last post by:
I have a cross tab query with Date as a row heading and a series of Names as column headings. The Value for each Date/Name intersection can either be -1, 0 or 1. For example: Date, Name1,...
1
by: Grumpy9999 | last post by:
I have a memo field that can shrink and grow. I have a report query that works fine. The report shows information for "Category" a, b and c. When I change the query by saying all I what is category...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.