Solved

Pulling Information into one table from another.

Posted on 2013-02-01
9
158 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
  • 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
 

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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
A short film showing how OnPage and Connectwise integration works.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

919 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

17 Experts available now in Live!

Get 1:1 Help Now