Reputation: 41
In 1 table I need to insert specific rows with specific values, according to other tables values.
UPDATE item_properties2 AS P
INNER JOIN items ON items.id = P.item
INNER JOIN item_groups ON item_groups.idp = items.group_id
SET P.nr = '0'
WHERE P.type = 1140614900 AND items_groups.idp = '1140503406';
This updates the table. But what I need is basically.
(id
, type
, item
, value
, shows
, nr
) VALUES
(78173, 1336983282, 1352706945, 'test Laisvai pastatomas Sharp', 0, 1)
item_properties2.Id - just row id,
item_properties2.type
- connect to item_property_groups2.id ,
'item_properties2.item' this connects to item.id ,
item.id have another column which is item.group_id ,
item.group_id is connected to item_groups.id which have another column naked item_groups.idp .
I need to only select items_groups.idp = '1140503406' . And basically i it should add rows in item_properties2 with with specific type value which i entered and only to models with specific item_properties2. item accord to item_groups.idp . I don't know how to do it.
Upvotes: 0
Views: 196
Reputation: 1649
there are some ways to insert a bulk of data from 2 tables into a newer table.
this can be done like this:
INSERT INTO item_properties2 (id, type, item, value, shows, nr)
SELECT Yid, Ytype,Yitem,Yvalue, Yshows, Ynr
FROM items
INNER JOIN item_groups ON item_groups.idp = items.group_id
WHERE items_groups.idp = '1140503406'
Instead of using the VALUES tag, you will now call for a specific select statement. you only need to change the Y values above into your own column names.
Or you could place your input into a stored procedure the above query will run over your 2 tables and will insert the values that go with the where statement into the 3th table.
CREATE PROCEDURE sInput
( @val1 int, @val2 int, @val3 varchar(10))
AS
INSERT INTO MyTable(val1, val2, val3)
VALUES(@val1, @val2, @val3)
return
Upvotes: 1