Insert data into table with result from another select query

后端 未结 3 1427
慢半拍i
慢半拍i 2020-11-30 22:58

I am seeking help on the following issue: I have two tables Table_1 columns are itemid, locationid, quantity

相关标签:
3条回答
  • 2020-11-30 23:31

    If table_2 is empty, then try the following insert statement:

    insert into table_2 (itemid,location1) 
    select itemid,quantity from table_1 where locationid=1
    

    If table_2 already contains the itemid values, then try this update statement:

    update table_2 set location1=
    (select quantity from table_1 where locationid=1 and table_1.itemid = table_2.itemid)
    
    0 讨论(0)
  • 2020-11-30 23:38
    INSERT INTO `test`.`product` ( `p1`, `p2`, `p3`) 
    SELECT sum(p1), sum(p2), sum(p3) 
    FROM `test`.`product`;
    
    0 讨论(0)
  • 2020-11-30 23:41

    Below is an example of such a query:

    INSERT INTO [93275].[93276].[93277].[93278] ( [Mobile Number], [Mobile Series], [Full Name], [Full Address], [Active Date], company ) IN 'I:\For Test\90-Mobile Series.accdb
    SELECT [1].[Mobile Number], [1].[Mobile Series], [1].[Full Name], [1].[Full Address], [1].[Active Date], [1].[Company Name]
    FROM 1
    WHERE ((([1].[Mobile Series])="93275" Or ([1].[Mobile Series])="93276")) OR ((([1].[Mobile Series])="93277"));OR ((([1].[Mobile Series])="93278"));
    
    0 讨论(0)
提交回复
热议问题