MySQL Problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
mattmcb
Forum Commoner
Posts: 27
Joined: Sun Jan 25, 2004 3:34 pm

MySQL Problem

Post by mattmcb »

Can someone tell me the correct syntax for this query:

Code: Select all

UPDATE products SET products.cat = cat2.cat_desc WHERE cat2.id = products.cat
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

UPDATE products,cat2 SET products.cat = cat2.cat_desc WHERE cat2.id = products.cat
Starting with MySQL 4.0.4, you can also perform UPDATE operations that cover multiple tables:

Code: Select all

UPDATE items,month SET items.price=month.price
WHERE items.id=month.id;
The example shows an inner join using the comma operator, but multiple-table UPDATE statements can use any type of join allowed in SELECT statements, such as LEFT JOIN.
Post Reply