Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

Consider I have 4 columns in a table and i have datas for 3 columns like below

TableTest

Col1  | Col2  | Col3
D11   | D12   |   
D21   | D22   | 

Normally the update query would be

Update TableTest SET Col1 = D11 , Col2 = D12 , COL3 = newdata Where Col1= D11

The Scenario is , the update query should only push data to the COL3 , it should skip the Col1 and Col2, as it has already filled with data(even if same or different data for the Col1 and Col2)

share|improve this question
    
provide sample example – hnn 17 hours ago
4  
If you just want to update Col3 you can just leave off the other cols, e.g. Update TableTest SET Col3 = newdata Where Col1= D11 – Quantumplate 17 hours ago
    
you can use .... SET Col2 = CASE WHEN Col2 = '' THEN 'newdata' ELSE Col2 END, ...... this assumes meaning of empty is '' if null is empty or also expected you may need to modify the WHEN accordingly – bansi 16 hours ago
    
" 56 rows and also also with thousands of records " So, does it have 56 or thousands? – Strawberry 15 hours ago
    
56 columns , it was my typing mistake – Niyaz 14 hours ago
up vote 7 down vote accepted

This might help -

UPDATE TableTest a
INNER JOIN TableTest b ON a.Col1 = b.Col1
SET a.Col3 = 'newData'
WHERE a.Col3 IS NULL

An INNER JOIN with the same table so that it updates the appropriate row!

share|improve this answer
    
i only know the one way that i have share in my answer this is good. – devpro 16 hours ago
    
UPDATE fetcheddata a INNER JOIN fetcheddata b ON a.OD_Order_ID_V = b.OD_Order_ID_V SET a.OD_Online_Listing_ID_V = 12 WHERE a.OD_Online_Listing_ID_V IS NULL and a.OD_Order_ID_V='CS44189505'; it doesnot helped me well – Niyaz 13 hours ago
    
Check if it is NULL or blank value. – Sougata 13 hours ago
    
UPDATE fetcheddata a INNER JOIN fetcheddata b ON a.OD_Order_ID_V = b.OD_Order_ID_V SET a.EM_Date_D = '2015-12-20' WHERE (a.EM_Date_D IS NULL or a.EM_Date_D='') and a.OD_Order_ID_V='CS44189505'; dude working great , i owe to thankfull to you. – Niyaz 12 hours ago

If you just want to update COL3 than don't include other columns in update query.

Query:

Update TableTest SET COL3 = newdata Where Col1= D11
share|improve this answer

You should update whole table using single query as:

Update TableSet SET COL3=CONCAT('D',CONVERT(Substr(Col2,2),INT)+1)

This will update table as follows:

TableTest

Col1  | Col2  | Col3
D11   | D12   |  D13 
D21   | D22   |  D23
share|improve this answer
    
Can u explain what it will do ? – Niyaz 16 hours ago
    
If it will work fine than its really new for me. – devpro 16 hours ago
    
I have updated my answer – Muhammad Muazzam 15 hours ago

Just do it, like this:

Update TableTest SET  COL3 = newdata Where Col1= D11
share|improve this answer
    
It's too short without a minimum of explanation. Please, add more comments on your answer to make it a complete one. – Luca Detomi 14 hours ago

In UPDATE query, there is no need to reassign the value of col1 and col2 if those values are not changing.

UPDATE TableTest 
SET COL3 = newdata 
WHERE Col1= 'D11';
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.