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!

Access Query 1

Status
Not open for further replies.

formrec

Technical User
Feb 8, 2006
6
US
Hi,

I'm doing a simple report whereby I am querying a table sorting the data,etc, but I want it to display all the possible values, rather than a subset (as its ultimatley going to be output to a chart)

For example at the moment I am getting this back

val Count
1 5
3 6

But would like it to give me

val Count
1 5
2 0
3 6
4 0

Any ideas would be greatly appreciated.

Regards

Jamie
 
Without looking at your query, and it might be a good idea to post it, you might do a left join on the table that has the val column. A left join would display all values...
 
Great thanks... I'll give that a go!
 
Ok....

Heres the query...

Tables

Main (all data)
Codes (values - with 4 options 1 - 4)

SELECT Codes.Code, Count(Main.S2_Q1) AS Count FROM Main INNER JOIN Codes ON Main.S2_Q1 = Codes.Val GROUP BY Codes.Code, Codes.Val ORDER BY Codes.Val;

Tried a left join but probably did it wrong....

Help please!
 
The implication appears to be that you have joined 2 (or more) tables in the query.
If you have, then you will need to ensure that the join properties for the appropriate links have been suitably modified, e.g. it may be necessary to establish the correct 'ALL:eek:nly' relationships.
 
SELECT Codes.Val, Count(*) AS Count
FROM Main RIGHT JOIN Codes ON Main.S2_Q1 = Codes.Val
GROUP BY Codes.Val
ORDER BY Codes.Val

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Can you post a few sample records from the main and codes table?
 
Sorry for not replying yesterday.

PHV's response is pretty much as far as I got, which in theory should work, but it seems to give slightly eratic data.

For example I have set the field S2_Q1 to all being 1, for 20 rows. The table Code.Val has the codes I will ultimaltely be using which has the values 1, 2, 3 and 4.

When I run this query it gives the following output.

Val Count
1 20 correct
2 1 ?
3 1 ?
4 1 ?

Any ideas why?

Thanks

Jamie
 
Sorry for the typo:
SELECT Codes.Val, Count(Main.S2_Q1) AS Count
FROM Main RIGHT JOIN Codes ON Main.S2_Q1 = Codes.Val
GROUP BY Codes.Val
ORDER BY Codes.Val

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks PHV. Works great now! It's easy when you know how!

Cheers

Jamie
 
Ahh, next bit. When I use this its fine, but if I add a HAVING or WHERE clause it seems to throw it back to how it was originally. Which does kind of make sense....

SELECT Codes.Code, Count(Main.S2_Q2) AS [Count]
FROM Main RIGHT JOIN Codes ON Main.S2_Q2 = Codes.Val
GROUP BY Main.HolRef, Codes.Code, Codes.Val
HAVING (((Main.HolRef)='abc1'))
ORDER BY Codes.Val;

This give

Code Count
Excellent 6
Good 6

but I want...

Code Count
Excellent 6
Good 6
Ok 0
Poor 0

Any help is appreciated!

Jamie
 
Perhaps this ?
SELECT Codes.Code, Count(Main.S2_Q2) AS [Count]
FROM Main RIGHT JOIN Codes ON Main.S2_Q2 = Codes.Val
WHERE Nz(Main.HolRef,'abc1')='abc1'
GROUP BY Codes.Code, Codes.Val
ORDER BY Codes.Val;

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top