A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

can't get query to group



 
 
Thread Tools Display Modes
  #1  
Old March 4th, 2010, 02:42 PM posted to microsoft.public.access.queries
gator
external usenet poster
 
Posts: 166
Default can't get query to group

here is the sql.

can someone help me determine why the query isn't grouping by GoupNumber?
The GroupName is the same for the GroupNumber. ID is unique.

SELECT Mid([ID],3,2) AS GroupNumber, Accounts.GroupName
FROM Accounts
GROUP BY Mid([ID],3,2), Accounts.GroupName, Accounts.ID
HAVING (((Accounts.ID) Like "01*"));

Example
ID GroupNumber GroupName
010101 01 red
010102 01 red
010201 02 blue
010301 03 green
  #2  
Old March 4th, 2010, 02:51 PM posted to microsoft.public.access.queries
Jerry Whittle
external usenet poster
 
Posts: 4,732
Default can't get query to group

It is grouping by "GroupNumber", then GroupName, then ID. Since ID is unique,
it will return every record. If you want to group by GroupNumber and
GroupName, run this:

SELECT Mid([ID],3,2) AS GroupNumber, Accounts.GroupName
FROM Accounts
GROUP BY Mid([ID],3,2), Accounts.GroupName
HAVING (((Accounts.ID) Like "01*"));

--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.


"gator" wrote:

here is the sql.

can someone help me determine why the query isn't grouping by GoupNumber?
The GroupName is the same for the GroupNumber. ID is unique.

SELECT Mid([ID],3,2) AS GroupNumber, Accounts.GroupName
FROM Accounts
GROUP BY Mid([ID],3,2), Accounts.GroupName, Accounts.ID
HAVING (((Accounts.ID) Like "01*"));

Example
ID GroupNumber GroupName
010101 01 red
010102 01 red
010201 02 blue
010301 03 green

  #3  
Old March 4th, 2010, 03:19 PM posted to microsoft.public.access.queries
gator
external usenet poster
 
Posts: 166
Default can't get query to group

error:
You tried to execute a query that does not include the specified expression
'Accounts.ID Like "01*"' as part of an aggregate function.

"Jerry Whittle" wrote:

It is grouping by "GroupNumber", then GroupName, then ID. Since ID is unique,
it will return every record. If you want to group by GroupNumber and
GroupName, run this:

SELECT Mid([ID],3,2) AS GroupNumber, Accounts.GroupName
FROM Accounts
GROUP BY Mid([ID],3,2), Accounts.GroupName
HAVING (((Accounts.ID) Like "01*"));

--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.


"gator" wrote:

here is the sql.

can someone help me determine why the query isn't grouping by GoupNumber?
The GroupName is the same for the GroupNumber. ID is unique.

SELECT Mid([ID],3,2) AS GroupNumber, Accounts.GroupName
FROM Accounts
GROUP BY Mid([ID],3,2), Accounts.GroupName, Accounts.ID
HAVING (((Accounts.ID) Like "01*"));

Example
ID GroupNumber GroupName
010101 01 red
010102 01 red
010201 02 blue
010301 03 green

  #4  
Old March 4th, 2010, 03:30 PM posted to microsoft.public.access.queries
vanderghast
external usenet poster
 
Posts: 593
Default can't get query to group

SELECT Mid([ID],3,2) AS GroupNumber, Accounts.GroupName
FROM Accounts
WHERE (((Accounts.ID) Like "01*"))
GROUP BY Mid([ID],3,2), Accounts.GroupName



Vanderghast, Access MVP





"gator" wrote in message
...
error:
You tried to execute a query that does not include the specified
expression
'Accounts.ID Like "01*"' as part of an aggregate function.

"Jerry Whittle" wrote:

It is grouping by "GroupNumber", then GroupName, then ID. Since ID is
unique,
it will return every record. If you want to group by GroupNumber and
GroupName, run this:

SELECT Mid([ID],3,2) AS GroupNumber, Accounts.GroupName
FROM Accounts
GROUP BY Mid([ID],3,2), Accounts.GroupName
HAVING (((Accounts.ID) Like "01*"));

--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.


"gator" wrote:

here is the sql.

can someone help me determine why the query isn't grouping by
GoupNumber?
The GroupName is the same for the GroupNumber. ID is unique.

SELECT Mid([ID],3,2) AS GroupNumber, Accounts.GroupName
FROM Accounts
GROUP BY Mid([ID],3,2), Accounts.GroupName, Accounts.ID
HAVING (((Accounts.ID) Like "01*"));

Example
ID GroupNumber GroupName
010101 01 red
010102 01 red
010201 02 blue
010301 03 green


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:11 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.