By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table Test_Table (
EID int,
Hold varchar(20),
Source varchar(50)
);
insert into Test_Table values
(3232 , 'KLME', 'jame.k@gmail.com'),
(null , 'KLME', 'https://google.com'),
(null , 'EEME', 'david.e@gmail.com'),
(null , 'JJIN', 'Test@gmail.com'),
(7232 , 'JJIN' , 'https://google.com');
5 rows affected
select t.Hold, s.Eid
from Test_Table t
inner join (
select Hold, max(EID) as Eid
from Test_Table
group by Hold
) s on s.Hold = t.Hold
Hold | Eid |
---|---|
EEME | null |
JJIN | 7232 |
JJIN | 7232 |
KLME | 3232 |
KLME | 3232 |
Warning: Null value is eliminated by an aggregate or other SET operation.
Update t
SET Eid = S.Eid
FROM Test_Table t
inner join (
select Hold, max(EID) as Eid
from Test_Table
group by Hold
) s on s.Hold = t.Hold
Warning: Null value is eliminated by an aggregate or other SET operation.
5 rows affected
SELECT *
from Test_Table
EID | Hold | Source |
---|---|---|
3232 | KLME | jame.k@gmail.com |
3232 | KLME | https://google.com |
null | EEME | david.e@gmail.com |
7232 | JJIN | Test@gmail.com |
7232 | JJIN | https://google.com |