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

  • Home
  • SEARCH
  • 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 842267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:55:54+00:00 2026-05-15T05:55:54+00:00

I don’t understand what this order_by clause is doing and whether I need it

  • 0

I don’t understand what this order_by clause is doing and whether I need it or not:

select c.customerid, c.firstname, c.lastname, i.order_date, i.item, i.price from 
items_ordered i, customers c 
where i.customerid = c.customerid
group by c.customerid, i.item, i.order_date
order by i.order_date desc;

This produces this data:

10330   Shawn   Dalton  30-Jun-1999 Pogo stick  28.00
10101   John    Gray    30-Jun-1999 Raft    58.00
10410   Mary Ann    Howell  30-Jan-2000 Unicycle    192.50
10101   John    Gray    30-Dec-1999 Hoola Hoop  14.75
10449   Isabela Moore   29-Feb-2000 Flashlight  4.50
10410   Mary Ann    Howell  28-Oct-1999 Sleeping Bag    89.22
10339   Anthony Sanchez 27-Jul-1999 Umbrella    4.50
10449   Isabela Moore   22-Dec-1999 Canoe   280.00
10298   Leroy   Brown   19-Sep-1999 Lantern 29.00
10449   Isabela Moore   19-Mar-2000 Canoe paddle    40.00
10413   Donald  Davids  19-Jan-2000 Lawnchair   32.00
10330   Shawn   Dalton  19-Apr-2000 Shovel  16.75
10439   Conrad  Giles   18-Sep-1999 Tent    88.00
10298   Leroy   Brown   18-Mar-2000 Pocket Knife    22.38
10299   Elroy   Keller  18-Jan-2000 Inflatable Mattress 38.00
10438   Kevin   Smith   18-Jan-2000 Tent    79.99
10101   John    Gray    18-Aug-1999 Rain Coat   18.30
10449   Isabela Moore   15-Dec-1999 Bicycle 380.50
10439   Conrad  Giles   14-Aug-1999 Ski Poles   25.50
10449   Isabela Moore   13-Aug-1999 Unicycle    180.79
10101   John    Gray    08-Mar-2000 Sleeping Bag    88.70
10299   Elroy   Keller  06-Jul-1999 Parachute   1250.00
10438   Kevin   Smith   02-Nov-1999 Pillow  8.50
10101   John    Gray    02-Jan-2000 Lantern 16.00
10315   Lisa    Jones   02-Feb-2000 Compass 8.00
10449   Isabela Moore   01-Sep-1999 Snow Shoes  45.00
10438   Kevin   Smith   01-Nov-1999 Umbrella    6.75
10298   Leroy   Brown   01-Jul-1999 Skateboard  33.00
10101   John    Gray    01-Jul-1999 Life Vest   125.00
10330   Shawn   Dalton  01-Jan-2000 Flashlight  28.00
10298   Leroy   Brown   01-Dec-1999 Helmet  22.00
10298   Leroy   Brown   01-Apr-2000 Ear Muffs   12.50

While if I remove the order_by clause completely, as in this query:

select c.customerid, c.firstname, c.lastname, i.order_date, i.item, i.price from 
items_ordered i, customers c 
where i.customerid = c.customerid
group by c.customerid, i.item, i.order_date;

I get these results:

10101   John    Gray    30-Dec-1999 Hoola Hoop  14.75
10101   John    Gray    02-Jan-2000 Lantern 16.00
10101   John    Gray    01-Jul-1999 Life Vest   125.00
10101   John    Gray    30-Jun-1999 Raft    58.00
10101   John    Gray    18-Aug-1999 Rain Coat   18.30
10101   John    Gray    08-Mar-2000 Sleeping Bag    88.70
10298   Leroy   Brown   01-Apr-2000 Ear Muffs   12.50
10298   Leroy   Brown   01-Dec-1999 Helmet  22.00
10298   Leroy   Brown   19-Sep-1999 Lantern 29.00
10298   Leroy   Brown   18-Mar-2000 Pocket Knife    22.38
10298   Leroy   Brown   01-Jul-1999 Skateboard  33.00
10299   Elroy   Keller  18-Jan-2000 Inflatable Mattress 38.00
10299   Elroy   Keller  06-Jul-1999 Parachute   1250.00
10315   Lisa    Jones   02-Feb-2000 Compass 8.00
10330   Shawn   Dalton  01-Jan-2000 Flashlight  28.00
10330   Shawn   Dalton  30-Jun-1999 Pogo stick  28.00
10330   Shawn   Dalton  19-Apr-2000 Shovel  16.75
10339   Anthony Sanchez 27-Jul-1999 Umbrella    4.50
10410   Mary Ann    Howell  28-Oct-1999 Sleeping Bag    89.22
10410   Mary Ann    Howell  30-Jan-2000 Unicycle    192.50
10413   Donald  Davids  19-Jan-2000 Lawnchair   32.00
10438   Kevin   Smith   02-Nov-1999 Pillow  8.50
10438   Kevin   Smith   18-Jan-2000 Tent    79.99
10438   Kevin   Smith   01-Nov-1999 Umbrella    6.75
10439   Conrad  Giles   14-Aug-1999 Ski Poles   25.50
10439   Conrad  Giles   18-Sep-1999 Tent    88.00
10449   Isabela Moore   15-Dec-1999 Bicycle 380.50
10449   Isabela Moore   22-Dec-1999 Canoe   280.00
10449   Isabela Moore   19-Mar-2000 Canoe paddle    40.00
10449   Isabela Moore   29-Feb-2000 Flashlight  4.50
10449   Isabela Moore   01-Sep-1999 Snow Shoes  45.00
10449   Isabela Moore   13-Aug-1999 Unicycle    180.79

I’m not sure what the order_by is doing here and if it’s having the intended effects.

  • 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-05-15T05:55:55+00:00Added an answer on May 15, 2026 at 5:55 am

    It looks like it is ordering on i.ordered_date, but using string comparison rather than date comparison, which is why 30-Jun-1999 is placed before 29-Feb-2000. As a string “30-Jun-1999” > “28-Feb-2000”, but as dates, the reverse is true.

    Check the type of i.ordered_date in the items_ordered table – it should be datetime or similar – if it’s varchar, then you will need to either change it to a date type, or cast the value to a date in the order-by clause. E.g.

       order by CAST(i.order_date AS DATE) desc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't understand where the extra bits are coming from in this article about
I don't remember whether I was dreaming or not but I seem to recall
I don't edit CSS very often, and almost every time I need to go
I don’t think I’ve grokked currying yet. I understand what it does, and how
I don't expect a straightforward silver bullet answer to this, but what are the
I don't know if anyone has seen this issue before but I'm just stumped.
I don't know when to add to a dataset a tableadapter or a query
I don't want PHP errors to display /html, but I want them to display
I don't want to take the time to learn Obj-C. I've spent 7+ years
I don't currently use ajax.net though I would be open to it if it

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.