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 > Update statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-10-08, 15:40
veparala veparala is offline
Registered User
 
Join Date: Jul 2006
Posts: 17
Update statement

Hi

I have two tables with the followinf data.

Employee1

EmpoyeeNo Name Role salary
111 John SSE 112220
222 rahim SE NULL
333 RAN DEV 583930


Employee2
EmpoyeeNo Name Role salary
111 John DBA 112220
222 rahim SEE 353664
333 RAN DEV 583930
444 rohit ADM 248299

I want to update Employee2 from Employee1. If any input column value has null value, then i don't want to updated that column (i.e keep the value as it is). If input value has not null, then i will updated that colum.

Now my final table (i.e Employee2) will looks like this after updation.

Employee2
EmpoyeeNo Name Role salary
111 John SSE 112220
222 rahim SE 353664
333 RAN DEV 583930
444 rohit ADM 248299

Please let me know the SQL for this updatation.
Reply With Quote
  #2 (permalink)  
Old 06-10-08, 18:13
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Code:
UPDATE employee2
SET    salary = e1.salary
FROM   employee2 e2
 INNER
  JOIN employee1 e1
    ON e1.employee_no = e2.employee_no
WHERE  e2.salary IS NULL
BTW, I believe you put your NULL salary in the wrong table in your sample data above.
__________________
George
Twitter | Blog
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