【问题标题】:SQL Query: Game server. If I break the query down, it works. If I put it all together, it failsSQL 查询:游戏服务器。如果我分解查询,它会起作用。如果我把它们放在一起,它会失败
【发布时间】:2013-01-24 00:52:43
【问题描述】:

查询是:

插入 char_inventory (charid,location,slot,itemid,quantity) 值(从 charid 不存在的字符中选择 charid (select charid from char_inventory where itemid=65535),0,0,65535,10000);

【问题讨论】:

  • 我将 () 放在从 chars 中选择的 charid 周围,我得到“你不能在 FROM 子句中指定目标表 'char_inventory' 进行更新

标签: sql sql-insert


【解决方案1】:

试试这个:

insert into char_inventory (charid,location,slot,itemid,quantity)
    select charid,0,0,65535,10000
    from chars
    where charid not in (select charid from char_inventory where itemid=65535)

【讨论】:

    【解决方案2】:

    将INSERT INTO...SELECT 语句与LEFT JOIN 一起使用

    INSERT INTO char_inventory (charid, location, slot, itemid, quantity) 
    SELECT  chars.charid, 0 , 0, 65535, 10000
    FROM    chars
            LEFT JOIN char_inventory
                ON  chars.charid = char_inventory.charid AND
                    char_inventory.itemid = 65535
    WHERE   char_inventory.charid IS NULL
    

    【讨论】:

      【解决方案3】:

      这个怎么样

      insert into char_inventory (charid,location,slot,itemid,quantity) 
      select charid,0,0,65535,10000 from chars where charid not in (select charid from char_inventory where itemid=65535)
      

      【讨论】:

        猜你喜欢
        • 2020-06-02
        • 2022-06-20
        • 1970-01-01
        • 2014-07-03
        • 2020-02-20
        • 1970-01-01
        • 1970-01-01
        • 2013-02-28
        • 1970-01-01
        相关资源
        最近更新 更多