Connecting Tech Pros Worldwide Forums | Help | Site Map

Custom sorting and grouping in a query

Jimmy Tran
Guest
 
Posts: n/a
#1: Nov 13 '05
Hello everyone,

I have a table with many columns. Two of them are VehicleNumber and
ShipDate. What I would like to do is sort all the data in ascending
date(ShipDate) but I also like to group the matching VehicleNumber
together at the same time(If they have same ShipDate; please note
grouping here means putting them in adjacent rows). VehicleNumber does
not need to get grouped together when they have different ShipDate. I
try simple queries but I keep getting "VehicleNumber not part of
aggregate function" and etc. Maybe my problem is because I am trying to
group VehicleNumber while my other fields have different values, as you
can see for example the Size column.

my sample table:
VehicleNumber ShipDate ... Size
123 9/9/2004 5
434 9/10/2004 5
123 9/9/2004 16
123 9/13/2004 4

my output query:
VehicleNumber ShipDate ... Size
123 9/9/2004 5
123 9/9/2004 16
434 9/10/2004 5
123 9/13/2004 4

Thank You a whole lot for helping me out.
Jim

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Squirrel
Guest
 
Posts: n/a
#2: Nov 13 '05

re: Custom sorting and grouping in a query


Hi Jimmy,

I think you have two choices here:

[1] A simple select statement with an 'order by' ShipDate, VehicleNumber,
Size.
This would return a sorted listing of every record.

[2] A 'group by' statement:
Select ShipDate, VehicleNumber from tablename Group By ShipDate,
Vehicle Number.
In this case you must omit the Size field.

Suggest you try both, look at the listings and see if either will meet your
needs.

HTH -Linda

"Jimmy Tran" <hunganh20@yahoo.com> wrote in message
news:414b4027$0$26153$c397aba@news.newsgroups.ws.. .[color=blue]
> Hello everyone,
>
> I have a table with many columns. Two of them are VehicleNumber and
> ShipDate. What I would like to do is sort all the data in ascending
> date(ShipDate) but I also like to group the matching VehicleNumber
> together at the same time(If they have same ShipDate; please note
> grouping here means putting them in adjacent rows). VehicleNumber does
> not need to get grouped together when they have different ShipDate. I
> try simple queries but I keep getting "VehicleNumber not part of
> aggregate function" and etc. Maybe my problem is because I am trying to
> group VehicleNumber while my other fields have different values, as you
> can see for example the Size column.
>
> my sample table:
> VehicleNumber ShipDate ... Size
> 123 9/9/2004 5
> 434 9/10/2004 5
> 123 9/9/2004 16
> 123 9/13/2004 4
>
> my output query:
> VehicleNumber ShipDate ... Size
> 123 9/9/2004 5
> 123 9/9/2004 16
> 434 9/10/2004 5
> 123 9/13/2004 4
>
> Thank You a whole lot for helping me out.
> Jim
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it![/color]


Jimmy
Guest
 
Posts: n/a
#3: Nov 13 '05

re: Custom sorting and grouping in a query


What if I need to have all the other fields in the query and I only
want to group by Vehicle # and order by SHIP DATE. Is it possible to
do without getting the aggregrate error from Access?
Pieter Linden
Guest
 
Posts: n/a
#4: Nov 13 '05

re: Custom sorting and grouping in a query


hunganh20@yahoo.com (Jimmy) wrote in message news:<fcfb6c66.0409200646.74cfb29d@posting.google. com>...[color=blue]
> What if I need to have all the other fields in the query and I only
> want to group by Vehicle # and order by SHIP DATE. Is it possible to
> do without getting the aggregrate error from Access?[/color]

Create a select query, include your totals query and then throw in any
fields you want. And while you're at it, have a beer and a smoke.
Closed Thread


Similar Microsoft Access / VBA bytes