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 can I optimize this?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-26-05, 07:15
gurpreets gurpreets is offline
Registered User
 
Join Date: Sep 2005
Posts: 2
How can I optimize this?

I have a table called `inidviduals` that have 10,000 records in the table and I want the query to change only the specific ones.

Table Structure is:
CREATE TABLE individuals (
`ID` int(10) unsigned NOT NULL default '0',
`Last_Name` varchar(255),
`Soundex_Code` varchar(10),
PRIMARY KEY (`ID`)
);

Current query is:
UPDATE individuals
SET Soundex_Code = CASE WHEN Last_Name = 'Aaron' THEN 'A650'
WHEN Last_Name = 'Abercrombie' THEN 'A162'
WHEN Last_Name = 'Aberlenc' THEN 'A164'
ELSE '' END;

Above query modifies ALL records, because of ELSE ''.

How can I optimize this to update only those records which matches in one query?

Last edited by gurpreets; 09-26-05 at 07:17.
Reply With Quote
  #2 (permalink)  
Old 09-26-05, 07:20
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
UPDATE individuals
SET Soundex_Code = CASE WHEN Last_Name = 'Aaron' THEN 'A650'
WHEN Last_Name = 'Abercrombie' THEN 'A162'
WHEN Last_Name = 'Aberlenc' THEN 'A164'
END
where Last_Name in ('Aaron','Abercrombie','Aberlenc')
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
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