Advertisement
pmkhlv

Untitled

May 8th, 2022
1,049
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. with forupdate as (
  2.     select ci.client_id, ci.client_firstname, ci.client_lastname, ci.client_email, ci.client_phone, ci.client_city, ci.age,
  3.         case
  4.             when c.age is null then 'I'
  5.         else 'U'
  6.         end as "action"
  7.     fROM
  8.         clients_inc as ci
  9.         left join clients as c
  10.         on ci.client_id = c.client_id
  11.         and (ci.client_firstname <> c.client_firstname
  12.         or ci.client_lastname <> c.client_lastname
  13.         or ci.client_email <> c.client_email
  14.         or ci.client_phone <> c.client_phone
  15.         or ci.client_city <> c.client_city
  16.         or ci.age <> c.age))
  17.  
  18. update clients
  19. set
  20.     client_firstname = forupdate.client_firstname,
  21.     client_lastname = forupdate.client_lastname,
  22.     client_email = forupdate.client_email,
  23.     client_phone = forupdate.client_phone,
  24.     client_city = forupdate.client_city,
  25.     age = forupdate.age
  26. from
  27.     clients c
  28.     inner join
  29.     forupdate
  30.     on c.client_id = forupdate.client_id
  31. where c.client_id = forupdate.client_id and "action" = 'U';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement