Solved

mysql update and get max(uploadDatetime)

Posted on 2015-01-05
2
395 Views
Last Modified: 2015-01-06
I have a query and I want to get the max datetime for the update does anyone know how I can do this

DROP Table if exists TEMP_PARTS;
CREATE TABLE TEMP_PARTS(SELECT  il.PartDesc as 'Tool Type', il.PartNumber, ip.Quantity, Cast('2012:01:01 12:00:00 AM'as DateTime) AS 'InsertDate', ip.InventoryListID, ip.locationID
                FROM Inventory_Parts as ip
                JOIN Inventory_InventoryList as il ON il.UID = ip.InventoryListID
                WHERE LocationID = 1 and isVisible = 1);
                
                UPDATE TEMP_PARTS tp
                JOIN Inventory_InventoryList as il ON il.UID = tp.InventoryListID
                JOIN Inventory_PartsHistory ph ON ph.InventoryListID = il.UID
//////I want tp.InsertDate = MAX(ph.InsertDate) WHERE///////////////////////////////// 
                Set tp.InsertDate = ph.InsertDate WHERE tp.PartNumber = il.PartNumber AND tp.LocationID = ph.locationID);
                
                SELECT * FROM TEMP_PARTS

Open in new window

0
Comment
Question by:r3nder
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 18

Accepted Solution

by:
Simon earned 500 total points
ID: 40532575
From what I can make out from your query (without table definitions) it looks like the UPDATE can be simplified to avoid the joins and just use a subquery to get the max(insertdate) for that item.

UPDATE TEMP_PARTS tp
Set tp.InsertDate = (select max(InsertDate) from inventory_PartsHistory WHERE InventoryListID = tp.InventoryListID AND  locationID=tp.LocationID);

Even if you DO need the join to Inventory_InventoryList, you'd still use a subquery to get the max(insertdate) from the Inventory_PartsHistory table.
0
 
LVL 6

Author Closing Comment

by:r3nder
ID: 40533506
Thanks Simon worked great
0

Featured Post

Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

690 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