Solved

MySQL Max date

Posted on 2015-01-27
2
398 Views
Last Modified: 2015-01-27
I am trying to get the max(date) from this query but it is not returning max
in the results the query returns this
2014-12-31 12:00:00  |  1008  | CO
but i know for a fact that this exists
2015-01-27 12:38:22  |  1008  | CO

Select MAX(UploadDate) as UploadDate,SerialNumber,ToolType FROM Inventory_SerializedAssets Where LocationID in(0) Group By SerialNumber);

Open in new window

0
Comment
Question by:r3nder
2 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 40573431
Don't know about MySQL, but in SQL Server the ToolType column is listed in the SELECT clause and not in the GROUP BY clause, so either add it to GROUP BY or remove it from SELECT.
SELECT MAX(UploadDate) as UploadDate, SerialNumber, ToolType 
FROM Inventory_SerializedAssets 
WHERE LocationID in(0) 
GROUP BY SerialNumber, ToolType

Open in new window

Also, just to check the box, verify for us the LocationID of the row with the date of '2015-01-27 12:38:22' to make sure it equal zero, as if it doesn't the WHERE clause would remove that row from the return set.
0
 
LVL 6

Author Closing Comment

by:r3nder
ID: 40573495
Thanks Jim
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Solution for warm standby SQL server 20 38
Make query more efficient 1 16
MSSQL: Replace text (typo) 7 31
Need a SQL Server 2014 plug-in to scan the DB schema 4 16
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now