sdfor
sdfor

Reputation: 6448

SQL Insert from another table

I can use some help with a sql INSERT.

words_table 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

Upvotes: 1

Views: 420

Answers (3)

Jonathan Nesbitt
Jonathan Nesbitt

Reputation: 466

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

Upvotes: 1

Dave Barker
Dave Barker

Reputation: 6437

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

Upvotes: 2

Abe Miessler
Abe Miessler

Reputation: 85056

Try this:

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

Upvotes: 4

Related Questions