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

x
?
Solved

MySQL - Query to edit field based on table join?

Posted on 2013-12-18
1
Medium Priority
?
398 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 2000 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

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

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

Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
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…
Suggested Courses
Course of the Month12 days, 5 hours left to enroll

916 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