Unix Technical Forum

update select question

This is a discussion on update select question within the MySQL General forum forums, part of the MySQL category; --> I have the following query... SELECT c.NLCID, n.publishdate FROM newsletter n JOIN newslettersection s using (NLID) JOIN newslettercontent c ...


Go Back   Unix Technical Forum > Database Server Software > MySQL > MySQL General forum

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 04:08 PM
Chris W
 
Posts: n/a
Default update select question

I have the following query...

SELECT c.NLCID, n.publishdate
FROM newsletter n
JOIN newslettersection s using (NLID)
JOIN newslettercontent c using(NLCID)
WHERE contenttype = 1 AND n.publishdate AND c.`timestamp` = '0000-00-00
00:00:00'

I want to run an update on newslettercontent and set its timestamp
column to be the publishdate from the newsletter table using the join
rules in that query. Is there a way to do that in a query? I should
probably just write a quick script to do it since I could probably do
that in less time than I have spent trying to figure out a query to do it.


--
Chris W
KE5GIX

"Protect your digital freedom and privacy, eliminate DRM,
learn more at http://www.defectivebydesign.org/what_is_drm"

Ham Radio Repeater Database.
http://hrrdb.com

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 04:08 PM
Sebastian Mendel
 
Posts: n/a
Default Re: update select question

Chris W schrieb:
> I have the following query...
>
> SELECT c.NLCID, n.publishdate
> FROM newsletter n
> JOIN newslettersection s using (NLID)
> JOIN newslettercontent c using(NLCID)
> WHERE contenttype = 1 AND n.publishdate AND c.`timestamp` = '0000-00-00
> 00:00:00'
>
> I want to run an update on newslettercontent and set its timestamp
> column to be the publishdate from the newsletter table using the join
> rules in that query. Is there a way to do that in a query?


yes, you can, see multi-table update

http://dev.mysql.com/doc/refman/5.0/en/update.html

--
Sebastian
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-17-2008, 04:08 PM
Ananda Kumar
 
Posts: n/a
Default Re: update select question

update newslettercontent c set c.timestamp= (select n.publishdate from
newsletter n where
n.NLCID= c.NLCID);

This should work.


On 4/16/08, Chris W <2wsxdr5@cox.net> wrote:
>
> I have the following query...
>
> SELECT c.NLCID, n.publishdate
> FROM newsletter n
> JOIN newslettersection s using (NLID)
> JOIN newslettercontent c using(NLCID)
> WHERE contenttype = 1 AND n.publishdate AND c.`timestamp` = '0000-00-00
> 00:00:00'
>
> I want to run an update on newslettercontent and set its timestamp column
> to be the publishdate from the newsletter table using the join rules in
> that query. Is there a way to do that in a query? I should probably just
> write a quick script to do it since I could probably do that in less time
> than I have spent trying to figure out a query to do it.
>
>
> --
> Chris W
> KE5GIX
>
> "Protect your digital freedom and privacy, eliminate DRM, learn more at
> http://www.defectivebydesign.org/what_is_drm"
>
> Ham Radio Repeater Database.
> http://hrrdb.com
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/mysql?unsub=anandkl@gmail.com
>
>


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 03:00 AM.


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