SELECT DISTINCT statement suddenly not sorting automatically as per usual.

Posted on 2007-07-20
Last Modified: 2012-06-27
I have an Access 2003 application that contains linked SQL2000 tables and a lot of VBA code automation.  I deployed it 2 weeks ago before going on vacation and when I returned yesterday was told that about 2 days ago (while I was still out) it had spontaneously begun losing some of the functionality and exhibiting odd quirks, among them a combo box for which the row source query is a SELECT DISTINCT statement had suddenly started showing up unsorted, which I have never seen before.  I can of course specify an ascending sort but have never before had to do so.  Nothing has changed with the back end SQL database or the Access interface.  The possible changes are automatic MS patches or possible local security changes  (we have been 'consolidated' and aren't usually notified of such changes anymore).  
Among a group of 5 users, these problems are not presenting in the same combinations from user to user and cropped up at different times from some users.  

In particular, can anyone think of what might have caused a SELECT DISTINCT result to suddenly stop sorting itself by default?  I'm wondering if something could be generally preventing Office2003/VBA/ODBC  from performing normally, and if I had an idea of what could be causing the un-sort, that would be a start.

Thanks for any ideas.  
Question by:jaw0807
    LVL 142

    Accepted Solution

    without ORDER BY , sorting is NOT guaranteed in any matter.
    if you want the records sorted, use ORDER BY

    the reason why DISTINT can, implicitely, sort the results is how it internally works.

    Author Comment


    As I say, I know that I can explicitly tell the select distinct query to sort.  What I have never seen is a select distinct result set, that had been reliably returning a sorted result for over a week without that explicit instruction, to suddenly (in the middle of a workday) start returning an unsorted result.  On another note, I have never personally seen a select distinct query NOT return a sorted result set, so this is very odd to my experience.

    Let me re-emphasize that this question is more about ferreting out what could have caused this (and the other problems) to suddenly spring up in a seemingly random manner than it is about the select distinct list itself.   Again, we are no longer in control of (or necessarily notified of) changes to the user machines and I am trying to figure out what Unkowns could be at work here so that I can ask The New Overlords specific questions about what might have changed, since just asking them "what's changed" doesn't get a very useful result.

    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    "what changed" , well, that is purely a matter of a threshold, as from when the engine processes a query in eventually a different way.
    DISTINCT will internally create a temporary table of the values to be "DISTINCT", but as from a certain moment on, the way to do that might change a little bit.
    LVL 4

    Expert Comment

    I had a similar problem when I upgraded an application from Access to SQL Server. In Access, GROUP BY would automatically sort. In SQL Server, you had to throw in an ORDER BY clause.
    LVL 1

    Expert Comment

    Forced accept.

    EE Admin

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Introduction In my previous article ( I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
    With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now