Solved

MySQL - Query to edit field based on table join?

Posted on 2013-12-18
1
380 Views
Last Modified: 2013-12-18
Hey,

I have a table of products, each with a "product_id" and a field called "weight".

There is a second table with "product_id" and "category_id".

I need to change the field "weight" to equal "2" for every product that has a  "category_id" of 5, 12, 15, 17 or 18.

Can any one help me build this example please?

Thank you
0
Comment
Question by:mhdi
1 Comment
 
LVL 10

Accepted Solution

by:
acbxyz earned 500 total points
ID: 39728172
This should do it:
update product_table set weight=2
where product_id in (
    select product_id
    from product_category_table
    where category_id in (5, 12, 15, 17, 18)
)

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
Creating and Managing Databases with phpMyAdmin in cPanel.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

919 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

14 Experts available now in Live!

Get 1:1 Help Now