Forum Discussion

CaMiller110's avatar
CaMiller110
Copper Contributor
Jul 13, 2023

SQL Query

Hi all, 

I have the the table, something like this: 

 

ID        Business      Price

1234       US              6

1234       MX             8

 

I want the logic that updates the table in this way: 

When ID is the same and business is 'MX', then it's price should be the amount of the same ID, but US business. So the result should look like: 

1234       MX             6

 

Thanks in advance!

 

  • olafhelper's avatar
    olafhelper
    Bronze Contributor

    I have the the table, something like this: 

    CaMiller110 , "something like"? A more precise would be fine. Next time, please post table design as DDL, some sample data as DML statement and the expected result.

    Update statement like this?

    UPDATE MX
    SET Price = US.Price
    FROM youTable AS US
         INNER JOIN
         yourTable AS MX
        ON US.ID = MS.ID
    WHERE US.Business = 'US'
          AND MX.Business = 'MX'

Resources