开发者

SQL Insert from another table

开发者 https://www.devze.com 2023-01-20 21:28 出处:网络
I can use some help with a sql INSERT. words_tab开发者_开发问答le contains productid word product table contains

I can use some help with a sql INSERT.

words_tab开发者_开发问答le contains
  productid
  word

product table contains
  productid
  description

I'd like to create a row in words_table that contains the productid and the word "foundit" for each row in product table WHERE description LIKE '%keyword%'.

and I'm not sure how to do it.

Thanks


Try this:

INSERT INTO words_table (productId, word)
   SELECT productId, 'foundit' 
   FROM product 
   WHERE description like '%keyword%'


INSERT INTO Words_table
SELECT ProductId, 'FoundIt'
  FROM Product
 WHERE Description LIKE '%keyword%'


INSERT  words_table (productid, word)
SELECT  productid, 'foundit'
FROM    product
WHERE   description LIKE '%' + @keyword + '%'
0

精彩评论

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