Solved

MYSQL update query

Posted on 2014-01-27
5
439 Views
Last Modified: 2014-01-30
MySQL UPDATE QUERY

hello I need help with an update query in MYSQL

I have 2 tables
c_item_property   (TABLE NAME)                             c_document  (TABLE Name
     c_id   int                                        1 to 1                      c_id    int
     ref   int                                          1 to 1                      id    int
     visibility    tinyint(4)                                                     path    varchar

ok... so between the 2 tables I need to update the c_item_property table
with the 1 to 1 relationship (i think it might be a join.. not sure) between c_id .....and the ref to id  1 to 1 relationship.

I need to update visibility to  1      when path =  '/week_03'

thanks for your help

FaithDan
0
Comment
Question by:FaithDan
  • 2
  • 2
5 Comments
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 200 total points
ID: 39813334
this article will explain how you need to write your UPDATE , though you must check out which syntax you need to pick for MySQL:
http://www.experts-exchange.com/Database/Miscellaneous/A_1517-UPDATES-with-JOIN-for-everybody.html
or directly the mysql reference for UPDATE:
http://dev.mysql.com/doc/refman/5.0/en/update.html
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39813337
in code, it might be something like this  
UPDATE c_item_property   ip, c_document  c
  SET ip.visibility = 1
WHERE ip.id = c.id
  AND c.path =  '/week_03'

Open in new window

0
 
LVL 1

Author Comment

by:FaithDan
ID: 39813730
Hello .. I have it working as below in a select query..

what do I need to do to the code to change it to the update query.  I need to update ip.visibility to 1

SELECT ip.visibility, c.path
FROM c_item_property ip
join c_document c on ip.c_id = c.c_id
AND ip.ref = c.id and (ip.c_id = 62 or ip.c_id = 63 or ip.c_id = 64)

WHERE

 c.title LIKE 'week 03'
LIMIT 0 , 90
0
 
LVL 40

Accepted Solution

by:
Sharath earned 300 total points
ID: 39814291
check this.
UPDATE  c_item_property ip, c_document c
         SET  ip.visibility = 1
 WHERE ip.c_id = c.c_id
        AND ip.ref = c.id
        AND ip.c_id IN (62,63,64)
        AND c.title LIKE 'week 03’
    LIMIT 0,90

Open in new window

0
 
LVL 1

Author Closing Comment

by:FaithDan
ID: 39821495
Thank you very much.  This worked perfecly
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

19 Experts available now in Live!

Get 1:1 Help Now