# OleDbCommand Order ASC within a group[Answered] RSS

## 2 replies

Last post Apr 09, 2016 06:24 PM by Ptolemy

• Ptolemy

Member

20 Points

96 Posts

### OleDbCommand Order ASC within a group

Apr 09, 2016 05:35 PM|Ptolemy|LINK

How can I order things within a group?

Let's say I have this table in Access:

Grp|Nr |
--------+
A | 2 |
A | 3 |
A | 1 |
--------+
B | 2 |
B | 3 |
B | 1 |
--------+
C | 2 |
C | 3 |
C | 1 |

How do I write tha comand so that I get this result?

Grp |Nr |
--------+
A | 1 |
A | 2 |
A | 3 |
--------+
B | 1 |
B | 2 |
B | 3 |
--------+
C | 1 |
C | 2 |
C | 3 |

I have tried this, but it doesn't work:

`"SELECT [Grp], [Nr] FROM [MyTable] GROUP BY [Grp] ORDER BY [Nr] ASC"`

As for now the output is:
1, 1, 1, 2, 2, 2, 3, 3, 3

But I want:
1, 2, 3, 1, 2, 3, 1, 2, 3

• PatriceSc

All-Star

47860 Points

17749 Posts

### Re: OleDbCommand Order ASC within a group

Apr 09, 2016 06:14 PM|PatriceSc|LINK

Hi,

You can sort on multiple columns. My understanding is that you just want ORDER BY [Grp],[Nr]

The weird thing here is that if you group, you'll get a single row for each group so what you shown shouldn't work (and it doesn't seems what you want. Mybe you are confgusiing sorting on a column and then on another or grouping multiple rows into one

• Ptolemy

Member

20 Points

96 Posts

### Re: OleDbCommand Order ASC within a group

Apr 09, 2016 06:24 PM|Ptolemy|LINK

Yes, I did confuse things. Actually I want an order within an order:

`"SELECT [Grp], [Nr] FROM [MyTable] ORDER BY [Grp] ASC, [Nr] ASC"`

That did the trick.