Jump to content

Recommended Posts

I'm trying to get dates out of the DB for an overtime system. The dates are for staff with the oldest seniority first to the newest staff last.
But when 2 or more people start on the same date. I need to randomly order them every time i make a query to the DB

In my database, there is a column called start_date.
I need to select all the dates in order of oldest date to newest date.
$sql = "SELECT * FROM staff ORDER BY start_date DESC";
That's easy BUT...
If there are 2 or more of the same start dates selected those dates in random order

OUTPUT Example:
1988-01-01 <-- oldest date
1988-02-02
1990-01-01
1990-05-05
2000-01-01 <-- these 3 in random order
2000-01-01 <-- these 3 in random order
2000-01-01 <-- these 3 in random order
2000-02-05
2005-12-12
2006-02-02 <-- these 5 in random order
2006-02-02 <-- these 5 in random order
2006-02-02 <-- these 5 in random order
2006-02-02 <-- these 5 in random order
2006-02-02 <-- these 5 in random order
2010-05-09
2019-01-14 <-- newest date
etc

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.