Solved

updating a MySQL table with ID numbers based on another table.

Posted on 2009-07-12
2
164 Views
Last Modified: 2012-05-07
I have 2 tables, one called 'products' and one called 'sub_cats'

in the table products there is a column 'sub_cats' which instead of having ID numbers as one would expect, it has the full name of the sub category, found in the sub_cats table.

I need to get the ID number from the sub_cats table and put it in the right fields which corresponds to the right name in the sub_cats table as indicated in the code area below.

Cheers!!

Tim


so its like...
 
products table:
 
ID,  sub_cat, title
1    knife   SK 1
2    fork    SF 1
3    fork    SF 2
4    spoon   SP 1
etc...
 
 
and in the sub_cats table its simply:
 
ID,  sub_cat
1    knife
2    fork
3    spoon
 
 
so I really need the products table to be more like:
 
ID,  sub_cat, title
1    1        SK 1
2    2        SF 1
3    2        SF 2
4    3        SP 1

Open in new window

0
Comment
Question by:timbo007
[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
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 24834671
this should do:
update products , sub_cats 
  set products.sub_cat = sub_cats.id
where products.sub_cat = sub_cats.sub_cat

Open in new window

0
 

Author Comment

by:timbo007
ID: 24834742
Hah, just as easy as that, I never thought of using join type syntax but it makes perfect sense!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

724 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