Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Pulling Information into one table from another.

Posted on 2013-02-01
9
Medium Priority
?
166 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
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
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 Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

885 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