If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > How to update with the same value

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-19-05, 04:59
archVille archVille is offline
Registered User
 
Join Date: Nov 2005
Posts: 40
How to update with the same value

I am trying to update and
update
set=
(select ....);

and in my select returns more than 1 rows(MSGubquery returns more than 1 rows).
For example if there are more than one same value in a cell that matches with select (4,4,4,4,4,4,4...) i want to put only the '4' in the value and not all the 4's!Thats why it hits an error but i dont know how to put only one of the same values in the cell.
Any idea?
Reply With Quote
  #2 (permalink)  
Old 12-07-05, 02:01
ramcha ramcha is offline
Registered User
 
Join Date: Oct 2004
Posts: 14
Use limit statement in your subquery to select the first record alone

Syntax:

UPDATE <tablename>
SET <colname> = (SELECT <colname> FROM <tablename> LIMIT 1);
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On