I\'ve got a table which looks something like this
ID | NAME | VALUE |
----------------------------
1 | Test | VALUE1 |
2 | Test2 |
Here's my go:
UPDATE test as t1
INNER JOIN test as t2 ON
t1.NAME = t2.NAME AND
t2.value IS NOT NULL
SET t1.VALUE = t2.VALUE;
EDIT: Removed superfluous t1.id != t2.id
condition.
UPDATE financialyear
SET firstsemfrom = dt2.firstsemfrom,
firstsemto = dt2.firstsemto,
secondsemfrom = dt2.secondsemfrom,
secondsemto = dt2.secondsemto
from financialyear dt2
WHERE financialyear.financialyearkey = 141
AND dt2.financialyearkey = 140
If you just need to insert a new row with a data from another row,
insert into ORDER_ITEM select * from ORDER_ITEM where ITEM_NUMBER =123;
Try this:
UPDATE data_table t, (SELECT DISTINCT ID, NAME, VALUE
FROM data_table
WHERE VALUE IS NOT NULL AND VALUE != '') t1
SET t.VALUE = t1.VALUE
WHERE t.ID = t1.ID
AND t.NAME = t1.NAME
Update MyTable
Set Value = (
Select Min( T2.Value )
From MyTable As T2
Where T2.Id <> MyTable.Id
And T2.Name = MyTable.Name
)
Where ( Value Is Null Or Value = '' )
And Exists (
Select 1
From MyTable As T3
Where T3.Id <> MyTable.Id
And T3.Name = MyTable.Name
)