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 342197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:46:50+00:00 2026-05-12T10:46:50+00:00

I have a table defined by: CREATE TABLE bar_table ( _id INTEGER NOT NULL

  • 0

I have a table defined by:

    CREATE TABLE bar_table (
        _id INTEGER NOT NULL PRIMARY KEY,
        index INTEGER NOT NULL DEFAULT '65535',
        _date DATE
    )

My basic select statement is:

SELECT * FROM bar_table ORDER BY <your-clause-here>

How do I order my selection by index ascending, and date descending? i.e. small indexes come before large indexes. In the event that two indexes are the same, the later date is to come first.

The documentation is pointing me towards COLLATion, ubut I’m not really sure what that is.

  • 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-12T10:46:51+00:00Added an answer on May 12, 2026 at 10:46 am

    While I know that you already have your own answer up here, I think it’s pertinent to go into the details at work here.

    First, the order by clause goes in order of columns or expressions specified. In this case:

    order by index asc, _date desc
    

    That sorts by index smallest to largest (ascending), and then _date largest to smallest (descending). While asc is the default value, I generally include it when I have multiple columns going opposite directions, like you do here.

    You can also include expressions in your order by:

    order by case when index < 0 then 1 else 0 end desc, _date desc
    

    This would put all of the negative index rows at the top, and then sort those by _date. Using expressions in your order by clause is very effective in certain circumstances.

    Now, you mentioned collation, and a little confusion as to what that is. Collation is how the database treats capital and accents in string comparisons. With a Captial-Sensitive collation, 'abc' != 'ABC'. However, with a Captial-Insensitive collation, 'abc' = 'ABC'.

    It should be noted that collation is not a character set. That’s usually determined by data type (varchar == ASCII, nvarchar == Unicode). Collation determines how strings are compared, not what character sets are available for use.

    Moreover, collation is also important with certain languages. Given a Latin collation, you just have to worry about capitalization and accents, but given a Danish collation, 'aa' = 'å'.1 So you can see that collation plays a big part in determining sorting and comparisons for different languages, as well.

    Collation is very important when ordering, because it determines how strings will be ordered given different capitalizations and accents. That’s why it keeps coming up in your searches. Collation is important, and it even affected StackOverflow this week!

    1: Thanks to Michael Madsen for pointing out this specific example.

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

Sidebar

Ask A Question

Stats

  • Questions 159k
  • Answers 160k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It does. IIRC this is a workaround for the lack… May 12, 2026 at 11:32 am
  • Editorial Team
    Editorial Team added an answer If all it is is one list in recurring meeting,… May 12, 2026 at 11:32 am
  • Editorial Team
    Editorial Team added an answer Currently you're always reading from the start of the file...… May 12, 2026 at 11:32 am

Related Questions

I am trying to learn how Hibernate works, and I am running into an
I am having a querying issue in Hibernate. I have a table, 'test', with
I have the unfortunate task of having to import data from excel into a
I'm trying to implement a price fallback system in SQL server. I'd like to
When working in Access, whenever I delete a record from one table - it's

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.