mstoehr Posted September 8, 2019 Share Posted September 8, 2019 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 Quote Link to comment Share on other sites More sharing options...
Barand Posted September 8, 2019 Share Posted September 8, 2019 ... ORDER BY start_date DESC, RAND() Quote Link to comment Share on other sites More sharing options...
mstoehr Posted September 8, 2019 Author Share Posted September 8, 2019 WOW so simple Thank you works great Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.