Friday, 27 September 2013

Insert data to table where select statement has more columns

Insert data to table where select statement has more columns

Hello i would like to add some rows from my pricelist table to products
table. I am trying to fill my products table by testing data. Is possible
to make query where i can add random amount of rows to my products table?
The main problem is that i have more rows in select statement than in
insert statement.
INSERT INTO products(product_name, product_price)
SELECT name_product, price_product, IF(RAND() > 0.2,1,0) AS random
FROM pricelist
HAVING random = 1
Thanks for your help i hope that it's clear

No comments:

Post a Comment