473,597 Members | 2,459 Online
Bytes | Software Development & Data Engineering Community
+ 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 2284
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.r r.com> wrote in message
news:28******** *************** ***@posting.goo gle.com... 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.r r.com> wrote in message
news:28******** *************** ***@posting.goo gle.com...
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
2683
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
44327
by: SoloCDM | last post by:
How do I keep my entire web page at a fixed width? ********************************************************************* Signed, SoloCDM
11
2649
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
1497
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 development. Disassembly into source code and preventing that from happening! Thinstall (thinstall.com) - I own it from previous projects (non - .NET) but don't have faith that it can single handedly protect my source code. What can I do to help,...
3
1705
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 Python is treating the function as a member function because the reference to it is in class scope.... Here's a simple case of what I'm trying (in the real code, fn is a function that returns a database connection relevant to that subclass): >...
7
2053
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 / pointers on keeping the DDL's in sync with each other. I'm going to have a development machine in my office that I first apply any schema / stored-procedure changes to, then would like to roll out
4
1547
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 software e.g. private Bitmap myTick = new Bitmap(@"C:\TempManager\tick.gif"); etc.... What I would like to do is have the contents of \TempManager become
22
2116
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 output for the user will be the form and the program will still run. In vb .NET, if i made it in the same way, will be no
19
2348
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 chunk of memory that it can use for it's own purposes. But on the "library" side, I want to be able to do some book-keeping for each memory block that I hand out. I want some "hidden" meta-data (that I keep in struct Container) to be associated...
1
1668
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 run this in IE everything seems fine, when I run it in Firefox the text runs out of the right box and the right box runs out of the overall container. I don't understand the reason for this??? I would like to make both columns the same height while...
0
7893
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8276
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8381
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8040
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6698
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5436
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3932
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2408
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1243
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.