Mr Banan Qry
New member
- Local time
- Today, 19:09
- Joined
- Jul 3, 2012
- Messages
- 9
Hi!
I'm trying to create ONE query which would fetch me the number of occurences on a particular value in a field while keeping duplicates.
For instance let's say i've got the following table
Color......Value
Red.........5
Red.........8
Orange....1
Then i would like to have the following result from my query
Color.........Value.......CountOfColor
Red............5..............2
Red............8..............2
Orange.......1..............1
I know i could achieve this by creating a view first. For instance by saving this expression as qryCountOfColors
And then make the following query
However I'm woundering wheter or not I could achieve it without creating the qryCountOfColors.
I'm :banghead: myself into a mental meltdown . I've been playing with the idea of creating of creating a subquery to achieve this but im unable to get to work
I would be extremely grateful if someone could help along and explain wheter or not it's posssible and if is how to go about it. It would allow me to go back to normal sleeping hours
I'm trying to create ONE query which would fetch me the number of occurences on a particular value in a field while keeping duplicates.
For instance let's say i've got the following table
Color......Value
Red.........5
Red.........8
Orange....1
Then i would like to have the following result from my query
Color.........Value.......CountOfColor
Red............5..............2
Red............8..............2
Orange.......1..............1
I know i could achieve this by creating a view first. For instance by saving this expression as qryCountOfColors
Code:
SELECT tblColors.Color, Count(tblColors.Color) AS CountOfColor
FROM tblColors
GROUP BY tblColors.Color;
Code:
SELECT tblColors.Color, tblColors.Value, qryCountOfColors.CountOfColor
FROM tblColors INNER JOIN qryCountOfColors ON tblColors.Color = qryCountOfColors.Color
However I'm woundering wheter or not I could achieve it without creating the qryCountOfColors.
I'm :banghead: myself into a mental meltdown . I've been playing with the idea of creating of creating a subquery to achieve this but im unable to get to work
Code:
SELECT tblColors.Color As BANANA, tblColors.Value, (SELECT Count(tblColors.Color) AS CountOfColor FROM tblColors GROUP BY tblColors.Color HAVING (((tblColors.Color)=BANANA))) AS Expr1
FROM tblColors;
I would be extremely grateful if someone could help along and explain wheter or not it's posssible and if is how to go about it. It would allow me to go back to normal sleeping hours
Last edited: