Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I combine SELECT function with UPDATE

Status
Not open for further replies.

robinantill

Technical User
Mar 22, 2001
6
GB
I need to select certain records and then replace then with a new value. I have been searching through the manual and also on this forum board but to no avail. I have tried loads of different combinations but can not find the answer.

I can select my records using the following:-

SELECT numcomments FROM wsnlinks_links WHERE numcomments < 53

And I can update my records using the following:-

UPDATE wsnlinks_links SET numcomments = 22

What I can't do is to combine these into one SQL query which is what I need.

I would appreciate some guidance to this with how do do this.

Thanks,
Robin
 
are you saying you want to completely reset everybody who's under 53 to all be exactly 22, no matter what they were before?

that's easy :)

Code:
UPDATE wsnlinks_links 
   SET numcomments = 22
 WHERE numcomments < 53
if that's not what you want, could you please explain more?

r937.com | rudy.ca
 
Hi,
I think I have solved this with the following:-

UPDATE wsnlinks_links numcomments SET numcomments=119
WHERE numcomments < 60


This updates numcomments to a value of 119 if the value of numcomments is less than 60

Thanks for any observations.

Regards,
Robin
 
Thanks r937,
Our posts crossed in cyberspace, and it is good we agree.
Regards,
Robin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top