473,480 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Keeping a non-alphabetical sort order

I have a table with records in a desired sort order (I appended them
to the table in the order I wanted). It would look something like
this:

Table 1
Name Date Code DisplayOrder
------ ------------ ----------- ------------------
A1 1-21-04 XB56 10
A1 1-21-04 XB56 20
A1 1-21-04 XB56 30
A2 1-21-04 CT57 40
C2 1-21-04 DF58 50
C1 1-21-04 NN59 60
B1 1-21-04 GJ60 70
B2 1-21-04 FT61 80
B2 1-21-04 FT61 90

I now run a SELECT DISTINCT query on this table - not including the
DisplayOrder field and I get:

Table 2
Name Date Code
------- ------------ -------------
A1 1-21-04 XB56
A2 1-21-04 CT57
B1 1-21-04 GJ60
B2 1-21-04 FT61
C1 1-21-04 NN59
C2 1-21-04 DF58

Here is my problem: I have to drop the DisplayOrder Column to get the
SELECT DISTINCT to run, but then it reorders the recordset. In this
case, it is now ordered by Name (alphabetically). Table 2 has the
data I want, just not in the order I want. Can anyone help?

Thanks in advance.

tom r
Nov 12 '05 #1
2 2279
Well, since you are using SELECT DISTINCT, there's no reason why the A1 and
B2 records need to have seperate entries for DisplayOrder use this instead:
Table 1
Name Date Code DisplayOrder
------ ------------ ----------- ------------------
A1 1-21-04 XB56 10
A1 1-21-04 XB56 10
A1 1-21-04 XB56 10
A2 1-21-04 CT57 40
C2 1-21-04 DF58 50
C1 1-21-04 NN59 60
B1 1-21-04 GJ60 70
B2 1-21-04 FT61 80
B2 1-21-04 FT61 80
Which will come out like this with SELECT DISTINCT ...
Name Date Code DisplayOrder
------ ------------ ----------- ------------------
A1 1-21-04 XB56 10
A2 1-21-04 CT57 40
C2 1-21-04 DF58 50
C1 1-21-04 NN59 60
B1 1-21-04 GJ60 70
B2 1-21-04 FT61 80
"tom r." <ri******@neo.rr.com> wrote in message
news:28**************************@posting.google.c om... I have a table with records in a desired sort order (I appended them
to the table in the order I wanted). It would look something like
this:

Table 1
Name Date Code DisplayOrder
------ ------------ ----------- ------------------
A1 1-21-04 XB56 10
A1 1-21-04 XB56 20
A1 1-21-04 XB56 30
A2 1-21-04 CT57 40
C2 1-21-04 DF58 50
C1 1-21-04 NN59 60
B1 1-21-04 GJ60 70
B2 1-21-04 FT61 80
B2 1-21-04 FT61 90

I now run a SELECT DISTINCT query on this table - not including the
DisplayOrder field and I get:

Table 2
Name Date Code
------- ------------ -------------
A1 1-21-04 XB56
A2 1-21-04 CT57
B1 1-21-04 GJ60
B2 1-21-04 FT61
C1 1-21-04 NN59
C2 1-21-04 DF58

Here is my problem: I have to drop the DisplayOrder Column to get the
SELECT DISTINCT to run, but then it reorders the recordset. In this
case, it is now ordered by Name (alphabetically). Table 2 has the
data I want, just not in the order I want. Can anyone help?

Thanks in advance.

tom r

Nov 12 '05 #2
By definition, records in a relational database table are unordered. Thus,
you need to specify _some_ field if you want them ordered in a particular
way.

You see them ordered by the name field, simply because it is convenient for
the database engine; they might, however, after some future release or
patch, be ordered differently or simply randomly.

Michael suggests that you can use the same DisplayOrder field based on the
Name field (neither Name nor Date, by the way, is an appropriate name for a
Field because both are Access reserved words and sooner or later, that will
be confusing). That would work for this particular query, but it may not be
appropriate for other situations in your application.

Have you considered not using a DISTINCT, but instead using a Totals Query,
selecting Group By for each field except Display Order which will be
"First", and selected for Sorting. I think that will do what you want.

Larry Linson
Microsoft Access MVP

"tom r." <ri******@neo.rr.com> wrote in message
news:28**************************@posting.google.c om...
I have a table with records in a desired sort order (I appended them
to the table in the order I wanted). It would look something like
this:

Table 1
Name Date Code DisplayOrder
------ ------------ ----------- ------------------
A1 1-21-04 XB56 10
A1 1-21-04 XB56 20
A1 1-21-04 XB56 30
A2 1-21-04 CT57 40
C2 1-21-04 DF58 50
C1 1-21-04 NN59 60
B1 1-21-04 GJ60 70
B2 1-21-04 FT61 80
B2 1-21-04 FT61 90

I now run a SELECT DISTINCT query on this table - not including the
DisplayOrder field and I get:

Table 2
Name Date Code
------- ------------ -------------
A1 1-21-04 XB56
A2 1-21-04 CT57
B1 1-21-04 GJ60
B2 1-21-04 FT61
C1 1-21-04 NN59
C2 1-21-04 DF58

Here is my problem: I have to drop the DisplayOrder Column to get the
SELECT DISTINCT to run, but then it reorders the recordset. In this
case, it is now ordered by Name (alphabetically). Table 2 has the
data I want, just not in the order I want. Can anyone help?

Thanks in advance.

tom r

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2677
by: Robert Oschler | last post by:
Hello, Given the following program: -------------- import re x = "The dog ran. The cat eats! The bird flies? Done." l = re.split("", x)
179
44225
by: SoloCDM | last post by:
How do I keep my entire web page at a fixed width? ********************************************************************* Signed, SoloCDM
11
2631
by: M Kinstlinger | last post by:
How can I assign a hover value and a link value, and maintain them if the link has been visited ? If I set up a visited link, the hover option is overrun - ??
5
1472
by: Mitchell Vincent | last post by:
I'm sure this has been discussed here plenty of times before (feel free to point me to the thread!) but I want to learn as much as possible about the single most talked about issue with .NET...
3
1697
by: Gregory Bond | last post by:
I'm building a class hierarchy that needs to keep as a class variable a reference to a (non-member) function, so that different subclasses can use different generator functions. But it seems...
7
2041
by: BarryS | last post by:
Hi All: We're rolling out 3 DB2 (8.2 on LUW) platforms for branch offices, each of these are going to have the same schema. These are all going to be non-federated systems. I need some advice...
4
1536
by: aaj | last post by:
Hi all I have a group of files that I store independently in a temporary folder on the c: drive. Typical things are ini files, bitmaps, icons etc. All access to the files is hardcoded within my...
22
2086
by: Vell | last post by:
Hi, i'm moving my first steps in vb.NET world and i'm getting first troubles.. in vb6 i can start an application from Sub Main() and load for example a form using 'set' and 'show' command. The...
19
2333
by: pinkfloydhomer | last post by:
Please read the example below. I'm sorry I couldn't make it smaller, but it is pretty simple. When client code is calling newThingy(), it is similar to malloc: the client gets a pointer to a...
1
1660
by: Sjef | last post by:
I am trying to understand the deeper meanings of containers. One would say: everything inside the container div will stay inside, but apparently that's not true. My test code is below. When I...
0
7041
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7081
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6737
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6921
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5336
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4776
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4481
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.