?
Solved

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

Posted on 2009-07-12
2
Medium Priority
?
166 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 1000 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
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…

770 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