开发者

Using a constant just once, in a SQL request

开发者 https://www.devze.com 2023-01-09 18:50 出处:网络
I am performing this request, and I get the results I want: UPDATE sales SET color = ( SELECT color FROM master

I am performing this request, and I get the results I want:

UPDATE sales 
   SET color = (
                SELECT color 
                  FROM master 
                 WHERE productcode = "XJ2"
               ) 
 WHERE productcode = "XJ2";

But now I use a BI transformation tool where I can enter the constant ("XJ2" 开发者_如何学JAVAhere) only once.

So I have to find an SQL request that does the same, but uses "XJ2" just once.

I feel some join is what I need, but I can't find a way to make it work (shame).

The point of this request is to retrieve the color of a product from a master table, to create a fully detailed table that I will use for data mining. Using MySQL, if that matters.


  UPDATE sales s
  INNER JOIN master m ON (m.ProductCode = s.ProductCode)      
  SET color= m.color
  WHERE s.productcode="XJ2"


UPDATE Sales
SET color = m.color
FROM Sales S
 INNER JOIN Master M
 ON M.ProductCode = S.ProductCode
WHERE S.ProductCode = 'XJ2'
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号