Solved

Pulling Information into one table from another.

Posted on 2013-02-01
9
157 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Creating and Managing Databases with phpMyAdmin in cPanel.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 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

22 Experts available now in Live!

Get 1:1 Help Now