Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Pulling Information into one table from another.

Posted on 2013-02-01
9
Medium Priority
?
164 Views
Last Modified: 2013-05-22
I have been banging my head in frustration over this novice issue.  I'm trying to update a column on table1 with information from table2 where two different variables match.... I'm better at drawing than I am describing this stuff, so, here we go.

Table1
Table1 pic
Table2
Table2 pic
Again, I'm trying to update the key1 column in Table1 based off of matching the cat and filename columns from Table1 to the ocat and key3 columns in Table2.
0
Comment
Question by:Jonathan CMCH
[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
  • 5
  • 4
9 Comments
 
LVL 12

Expert Comment

by:Jared_S
ID: 38843660
Try this:

update table1
set table1.key1 = table2.okey1
from table1 inner join table2
on table1.cat = table2.ocat and table1.filename = table2.okey3
0
 

Author Comment

by:Jonathan CMCH
ID: 38843847
Thanks Jared.

I don't think that it likes the 'from' syntax in there as I am getting an error.  I think you have me on the right track though with the inner join command.  I've attempted:

update table1
inner join table2
on table1.cat = table2.ocat
set table1.key1 = table2.okey1
where table1.filename = table2.okey3

but this is not pulling over any information from the table2.okey1 column.
0
 
LVL 12

Expert Comment

by:Jared_S
ID: 38843904
I gave you the wrong flavor of sql.. sorry. This should work.

UPDATE table1, table2
  SET set table1.key1 = table2.okey1
 WHERE  table1.filename = table2.okey3
  AND table1.cat = table2.ocat
0
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.

 

Author Comment

by:Jonathan CMCH
ID: 38844382
Thanks again.

That's actually the first query I tried to run.  Unfortunately, it's still not pulling any information from the table2.okey1 column.  I'm still unsure why.
0
 
LVL 12

Expert Comment

by:Jared_S
ID: 38844467
Any error messages?
0
 

Author Comment

by:Jonathan CMCH
ID: 38844474
No, the query runs.  It's just not pulling the information from the column.  0 rows are being edited, is what is reported.  I probably need to triple check to make sure those columns are comparable, but I'm pretty sure they are.
0
 
LVL 12

Expert Comment

by:Jared_S
ID: 38844561
If that doesn't fix it, maybe try running it as a select and confirm that the are rows that should be updated with the join criteria used.
0
 

Accepted Solution

by:
Jonathan CMCH earned 0 total points
ID: 38857239
Whelp, I found out what the issue was.  When I imported the csv file with the information into the database, it created a new line after the data in the last column of the table.  Therefore, even though the data looked the same in the two columns, when compared, they didn't match.  I corrected that new line issues and, voila... My 3 day migraine is gone.

Thanks for the help!
0
 

Author Closing Comment

by:Jonathan CMCH
ID: 39186879
Trial and error figured this one out....3 days of it.
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

705 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