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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:05:18+00:00 2026-05-31T08:05:18+00:00

My website displays posts by DATE even though the SQL table is ordered by

  • 0

My website displays posts by DATE even though the SQL table is ordered by ID. Since the order of the ID is not always the same as the order of the DATE, I run the query with ORDER BY 'DATE'.

SQL Table Example:

----------------------------
| ID | DATE                |
----------------------------
| 1  | 2011-10-20 00:00:00 | 
| 2  | 2012-10-20 00:00:00 |
| 3  | 2010-10-20 00:00:00 |
| 4  | 2011-09-20 00:00:00 |
----------------------------

To query I use: SELECT * FROM `table` ORDER BY 'DATE';

My questions:

  1. Would it benefit the query performance if the cluster index or primary key of the table was the DATE column?

  2. Is it possible to have the ID column auto-increment when it is not the primary key?

What I want to do is make the query as fast as possible (which I think would be possible by making the DATE the cluster index or primary key) but also allow each post to have a unique auto-increment ID. I tried to make DATE the primary key but I got an error saying “there can be only one auto column and it must be defined as a key”.

  • 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-31T08:05:19+00:00Added an answer on May 31, 2026 at 8:05 am

    I would not define the date as a primary key, but rather add an index on the field. Unique, if needed. I believe it is possible to have an autoincrement on a non primary key field, but trying it yourself will give you the best answer!

    <– EDIT –>

    To answer your comment question, I can’t say its a BAD idea, but dates are always picky. For once, you have to decide if you use UTC or local date, preview how daylight saving time affects your program, foresee if the need of a date update would be possible at some time of the application life, and things like that. I rather forget about that and just go with the unique autogenerated key.
    If you do go for the date as PK, you can use timestamp and avoid the second sequence column.

    I found more info about dates as primary keys at techtarget.com and made2mentor.com.

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

Sidebar

Related Questions

I have a Rails app with some basic models. The website displays data retrieved
Imagine an ASP.NET website which displays stock prices when a user logs in. Can
I have an ASP.Net hosted website which displays a list of results as a
I'm setting up a website which ultimately displays videos. The video files are all
Setup I have a website that draws RSS feeds and displays them on the
With LINQ to SQL in a ASP.NET MVC website I can display objects (records)
I am developing wordpress website where i display the latest 3 posts items (based
I did not include my website url, it is a vbulletin forum and all
My cookie is working fine i m not mentioning date so when the browser
I am trying to create a comment form for posts on my website. I

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.