Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7963089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:31:41+00:00 2026-06-04T05:31:41+00:00

I want my SQL to return all records for a given date, with the

  • 0

I want my SQL to return all records for a given date, with the most recent one on top (the column I’m ordering by contains both date and time – contains entries such as “5/21/2012 11:48:04 AM”).

I would think my sql (below) would do this. However, the actual results disregard the time element. They are returned like this:

5/21/2012 10:48:04 AM
5/21/2012 10:12:04 AM
5/21/2012 9:48:04 AM
5/21/2012 10:54:04 AM
5/21/2012 11:48:04 AM
...

(IOW, the results returned are just randomly ordered, as far as the time element goes)

the query is:

SELECT ENTRYDATE ENTERED, ENTEREDBYABC ABC
FROM 
   SomeTable v 
   LEFT JOIN SomeTable w ON v.someCol = w.someCorrespondingCol
WHERE
   ABC = :abc AND ENTRYDATE = trunc(sysdate) 
ORDER BY ENTERED DESC

UPDATE

More specific query and results:

This (column and table names have been changed):

SELECT ENTRYDATE ENTERED, ENTEREDBYABCID ABCID, COMMENTS
FROM 
  WHITMAN.HOLLOWSKY@ATTORNEY v 
  LEFT JOIN ABCworker w ON v.enteredbyabcid = w.abcid
WHERE
  ABCID = 124393 AND ENTRYDATE = TRUNC(sysdate) 
ORDER BY ENTRYDATE desc

…returns records with:

ENTERED     ABCID   COMMENTS
5/21/2012   1234    At 1:36 PM, ...
5/21/2012   1234    At 1:36 PM, ...
5/21/2012   1234    At 9:23 AM, ...
5/21/2012   1234    At 11:07 AM, ...
5/21/2012   1234    At 11:12 AM, ...
5/21/2012   1234    At 1:42 PM, ...
5/21/2012   1234    At 11:02 AM, ...
5/21/2012   1234    At 9:19 AM, ...
. . .

UPDATED AGAIN

With the query:

select entrydate from WHITMAN.HOLLOWSKY@ATTORNEY order by entrydate desc

I get:

5/21/2012 3:15:50 PM
5/21/2012 3:15:35 PM
5/21/2012 3:15:25 PM
5/21/2012 3:15:25 PM
5/21/2012 3:14:31 PM
5/21/2012 3:14:22 PM
5/21/2012 3:14:11 PM
. . .

IOW, it works just fine.

Whether “entrydate” is a DateTime column – I reckon so, but I don’t have privileges to look at the table structure, so … ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T05:31:42+00:00Added an answer on June 4, 2026 at 5:31 am

    Your ORDER BY is being honored. The problem is that the time component on all 11 rows that you are selecting must be midnight in order to satisfy the predicate

    entrydate = TRUNC(sysdate) 
    

    The query

    SELECT ENTRYDATE ENTERED, ENTEREDBYABCID ABCID, COMMENTS
      FROM WHITMAN.HOLLOWSKY@ATTORNEY v 
           LEFT JOIN ABCworker w ON v.enteredbyabcid = w.abcid
     WHERE ABCID = 124393 
       AND ENTRYDATE = TRUNC(sysdate) 
     ORDER BY ENTRYDATE desc
    

    asks for all the rows where entrydate is today at midnight, then sorts on entrydate. By definition, since there is only one possible value for entrydate that satisfies the predicate, that ORDER BY is irrelevant. All 11 rows have exactly the same value for entrydate so sorting on that value produces an arbitrarily ordered result. Oracle could, quite correctly, return the 11 rows in any order and still be honoring your ORDER BY clause.

    Perhaps you want to order by the time that is stored in the comments column rather than the entrydate. Perhaps you want to change your predicate to return all the rows where entrydate was some time today.

    AND trunc(entrydate) = trunc(sysdate)
    

    Perhaps you want to do something else.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to return a relatively large number of records from SQL Express 2008
I want to make a SQL query that gets todays date and the most
I am developing an ASPX file to return all records from a SQL table.
I'm having trouble with my SQL SELECT statement. Basically I want to return all
Using SQL Server 2005 I want to filter the column where column value not
I'm trying to write a HQL/Criteria/Native SQL query that will return all Employees that
Given a list of parents and their children I want to return a list
What I want to do is retrieve all emails from MS SQL Customer table
I have 2 sql tables Table name: agents contains a records with a coloumn
I want to send SQL server Dashboard & Health Report to my client on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.