Dear Nova:
I built a database with your 2 tables, entered the data, and tested. I got
the results you suggest you wanted.
The query is:
SELECT A.val1, A.val2, COUNT(*) AS Counted
FROM TableA A, TableB B
WHERE B.valRef BETWEEN A.val1 AND A.val2
GROUP BY A.val1, A.val2
The result of running this query are:
Query1 val1 val2 Counted
1 8 5
2 8 5
3 8 5
4 8 4
5 8 3
5 11 4
I believe this may be what you wanted.
Note I used Aliasing for the names of the two tables. That means I have
used A for "TableA" and B for "TableB".
I also cheated and took the space out of your table names. It just makes
for extra typing and I can't read my own queries if I do this this way. If
you use spaces in table names you must bracket [] them all the time. All
the more reason to use aliases then.
Please let me know if this helped, and if I can be of any further
assistance. Perhaps you might want to know how this works.
Tom Ellison
Microsoft Access MVP (watch out! I'm back!)
Nova said:
Thank you for answer but yoyr query shows sum of count.
This is my data in table A and B
Table A Table B
val1 val2 valRef
1 8 3
2 8 4
3 8 5
4 8 6
5 8 7
5 11 10
I want to see 3 fields query result as below
val1 val2 CountResult
1 8 5 between 1-8
in Table B is 3,4,5,6,7
2 8 5 between 2-8
in Table B is 3,4,5,6,7
3 8 5 between 3-8
in Table B is 3,4,5,6,7
4 8 4 between 4-8
in Table B is 4,5,6,7
5 8 3 between 5-8
in Table B is 5,6,7
5 11 4 between 5-11
in Table B is 5,6,7,10
Help me again please.