我试图在MYSQL中执行以下插入但它失败了。
INSERT INTO TABLE_A(M_DATE,T_M_ID,I_M_ID)
(
'2015-05-16',
SELECT T_ID FROM TWD WHERE T_NAME = 'abc',
SELECT I_ID FROM IWD WHERE I_NAME = 'dfgh34sd78'
);
表TABLE_A还具有自动增量M_ID字段
有关如何解决这个问题的想法吗?
ERROR
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''2015-05-16',
SELECT T_ID FROM TWD WHERE T_NAME = 'abc',
' at line 3
答案 0 :(得分:1)
您可以尝试以下方式:
INSERT INTO TABLE_A (M_DATE,T_M_ID,I_M_ID) VALUES
(
'2015-05-16',
(SELECT T_ID FROM TWD WHERE T_NAME = 'abc' LIMIT 1),
(SELECT I_ID FROM IWD WHERE I_NAME = 'dfgh34sd78' LIMIT 1)
);
答案 1 :(得分:0)
我最终将所有这些新线路移动到一个单独的线路中。使用SET.
它正在运作。这是适合我的。
INSERT INTO `TABLE_A` SET M_DATE = '2015-05-16', T_M_ID = (SELECT T_ID FROM TWD WHERE T_NAME='abc'),I_M_ID = (SELECT I_ID FROM IWD WHERE I_NAME='dfgh34sd78');