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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:06:19+00:00 2026-06-09T11:06:19+00:00

I recently took over some work form another developer and am trying to understand

  • 0

I recently took over some work form another developer and am trying to understand why a specific sql query does not work for certain timestamps, more specifically timestamps on the same date, the sql query is:

select FROM_UNIXTIME(order_time,'%Y.%m.%D') as order_time,
       order_time as timealias
  from orders
  where order.id ='.$user->id.'
  group by FROM_UNIXTIME(order_time,'%Y.%m.%D')
  order by timealias desc

The idea is that the orders are grouped by date for the user to view, if the dates are on different days.

This works fine:

03/08/2012, 15:10:30 (Unix Timestamp: 1344006630)
04/08/2012, 12:10:30 (Unix Timestamp: 1344082230)

However, if they are on the same day but at different times, then it displays the first order in the table but the second.

03/08/2012, 15:10:30 (Unix Timestamp: 1344006630)
03/08/2012, 17:30:25 (Unix Timestamp: 1344015025)

My theory is that it does not recognise the second entry’s date as a match to the first entry’s, but since that date is used already it breaks, or something to that effect. But considering DBs aren’t my strongpoint, it’s a guess.

If anyone knows a proper reason why it behaves like this, I would really appreciate some insight.

  • 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-06-09T11:06:20+00:00Added an answer on June 9, 2026 at 11:06 am

    Your query contains a GROUP BY on FROM_UNIXTIME. This is going to pick one “random” row for each FROM_UNIXTIME, which isn’t what you want.

    If you want to see every timestamp, including duplicates:

    "select FROM_UNIXTIME(order_time,'%Y.%m.%D') as order_time, order_time as timealias from orders where order.id ='".$user->id."' order by timealias desc"
    

    If you want to show the number of order for each FROM_UNIXTIME:

    "select FROM_UNIXTIME(order_time,'%Y.%m.%D') as order_time, order_time as timealias, COUNT(*) order_cnt from orders where order.id ='".$user->id."' group by 1 order by timealias desc"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I encountered a bug in an application I took over from another developer.
Just recently took over a project from my developer. I'm a noob to coding,
I recently took over a project and they have a SQL job setup to
I recently took over a project that has a pretty dirty database... The table
I recently took over management of a Windows 2003 server. The application log is
So, I took over an existing WinForms app recently. We need to change it
I recently took up learning some css... and I am getting stuck on some
Recently I took a test at brainbench and got not a bad result (something
I recently took over a GWT project and began making necessary changes. Everything was
I recently took over a project that a colleague was working on and 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.