Solved

Update table using MySQL

Posted on 2014-09-16
2
228 Views
Last Modified: 2014-09-16
I am updating a table I create and the error I get is improper syntax near ' ' line 2.
The table has been created,  the data from the first 2 inserts are there but the update has not done its part
can anyone guide me in the right direction
DROP TABLE IF EXISTS LKLTN;
CREATE TABLE LKLTN(
ToolNumber int,
LastOfLocation int,
MaxOfUploadTime Varchar(20),
JobType Varchar(10),
Company Varchar(50),
Rig Varchar(50),
RigNumber Varchar(20),
City Varchar(50),
State Varchar(60)
);
Insert INTO LKLTN (ToolNumber,LastOfLocation,MaxOfUploadTime,JobType)
SELECT sa.SerialNumber as 'ToolNumber', Max(JobDownholeEquipment.JobID) AS 'LastOfLocation', Max(JobDownholeEquipment.StartTime) AS 'MaxOfUploadTime',
'Job' AS JobType
FROM SerializedAssets AS sa 
INNER JOIN JobDownholeEquipment ON sa.SerialNumber = JobDownholeEquipment.ToolNumber
GROUP BY sa.SerialNumber, sa.ToolType
HAVING sa.ToolType='TN';


INSERT INTO LKLTN(ToolNumber,LastOfLocation,MaxOfUploadTime,JobType)
SELECT ToolAssemblies.ToolNumber AS ToolNumber, MAX(ToolAssemblies.Location) AS 'LastOfLocation', Max(ToolAssemblies.UploadTime) AS 'MaxOfUploadTime', 'Assembly' AS JobType
FROM ToolAssemblies 
GROUP BY ToolAssemblies.ToolNumber;
Update LKLTN <--------Start here
JOIN Job as j ON LKLTN.LastOfLocation = j.JobID;
SET
LKLTN.Company = j.Company,
LKLTN.Rig = j.Rig,
LKLTN.RigNumber =  j.RigNumber, 
LKLTN.WellName = j.WellName,
LKLTN.City = j.City,
LKLTN.State = j.State

WHERE LKLTN.LastOfLocation = j.JobID;

SELECT * FROM LKLTN GROUP BY ToolNumber

Open in new window

0
Comment
Question by:r3nder
2 Comments
 
LVL 47

Accepted Solution

by:
Vitor Montalvão earned 500 total points
ID: 40325658
You have a ';' before the SET keyword. Remove it:
Update LKLTN 
JOIN Job as j ON LKLTN.LastOfLocation = j.JobID
SET
LKLTN.Company = j.Company,
LKLTN.Rig = j.Rig,
LKLTN.RigNumber =  j.RigNumber, 
LKLTN.WellName = j.WellName,
LKLTN.City = j.City,
LKLTN.State = j.State
WHERE LKLTN.LastOfLocation = j.JobID;

Open in new window

0
 
LVL 6

Author Closing Comment

by:r3nder
ID: 40325692
Thanks Vitor - its always the little things!
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

786 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