Unix Technical Forum

How to write a single UPDATE statement for this situation?

This is a discussion on How to write a single UPDATE statement for this situation? within the MySQL forums, part of the Database Server Software category; --> Hi, I'm running MySQL 5.0 lon Linux. I have two tables ... PRODUCTS ----------------- ID INTEGER NOT NULL PRICE ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 11:23 AM
laredotornado@zipmail.com
 
Posts: n/a
Default How to write a single UPDATE statement for this situation?

Hi,

I'm running MySQL 5.0 lon Linux. I have two tables ...

PRODUCTS
-----------------
ID INTEGER NOT NULL
PRICE FLOAT UNSIGNED NOT NULL
PRIMARY KEY (ID)

CUSTOM_PRICES
---------------------------
ID INTEGER NOT NULL
PRODUCT_ID INTEGER NOT NULL
PRICE FLOAT UNSIGNED NOT NULL
PRIMARY KEY (ID)
FOREIGN KEY PRODUCT_ID REFERENCES PRODUCTS(ID)

The table "CUSTOM_PRICES" will have a subset of products from the
products table. What I want to do is update the price in the PRODUCTS
table with the corresponding entry from the CUSTOM_PRICES table,
assuming there is one. If there is not a corresponding entry in the
CUSTOM_PRICES table, I would like the price value in the PRODUCTS
table to remain unchanged.

How can I do this in a single UPDATE statement?

Thanks, - Dave

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:24 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com