Solved

Pulling Information into one table from another.

Posted on 2013-02-01
9
161 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

740 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