Reputation: 2783
I need to write the following query so the "att" field is always a constant.
INSERT INTO index(id,val,att) (SELECT ID,val FROM product), 14;
"14" is a constant
how would i write it, if even possible?
Upvotes: 0
Views: 66
Reputation:
INSERT INTO table_name(id,val,att) SELECT ID,val,14 FROM product
Dont use table name like index and there is no need for () in select from table.
Upvotes: 0
Reputation: 4456
INSERT INTO `index`(id,val,att) SELECT id,val,14 FROM product
Index is not a very good name for a table btw... You can use backquotes (`) to escape it, but better pick up another name.
Upvotes: 4
Reputation: 79929
INSERT INTO `Index`(id, val, att)
SELECT ID, val, 14
FROM Product
Upvotes: 1
Reputation: 6872
You can simply select a number and it will be returned. This should work:
INSERT INTO `index`(id,val,att) SELECT ID,val,14 FROM product;
Notes:
Upvotes: 1
Reputation: 195
INSERT INTO index(id,val,att) VALUES (SELECT id,val,14 FROM product)
Try it
Upvotes: 0
Reputation: 51640
Just add the constant in the SELECT
statement
INSERT INTO `index`(id, val, att) (SELECT ID, val, 14 FROM product);
Upvotes: 2
Reputation: 57573
You could use this:
INSERT INTO `index` (id,val,att)
SELECT ID,val,14 FROM product
Upvotes: 1