question

sunilsql47 avatar image
sunilsql47 asked

Update statement with joins

Hello, I am new to SQL. Here is my requirement ![alt text][1] [1]: /storage/temp/1627-capture. UPDATE Target_table SET MOBILE_USER_ID = A.MOBILE_USER_ID , TV_USER_ID = A.TV_USER_ID FROM Target_table INNER JOIN ( SELECT STORE_ID , CASE WHEN PRODUCT = 'MOBILE' THEN USER_ID END AS MOBILE_USER_ID , CASE WHEN PRODUCT = 'TV' THEN USER_ID END AS TV_USER_ID FROM source_Table ) A ON Target_table.STORE_ID = A.STORE_ID Please help me out, Thanks in advance
updatejoinsnew
capture.png (8.4 KiB)
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
CirqueDeSQLeil avatar image
CirqueDeSQLeil answered
This is a sample of code that can help you get the rest of the update working properly. SELECT STORE_ID ,[mobile] as MOBILE_USER_ID,[tv] as TV_USER_ID FROM (select store_id,user_id,product From #Source) s PIVOT (MAX(user_ID) for product in (mobile,tv) )as pvt
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.