试试这个:
SQL查询:
INSERT INTO `dictionary2` (word,verb)
SELECT word, (select @number :=1)
FROM `dictionary1`
WHERE `dictionary1`.word LIKE "t%"
AND `dictionary1`.word NOT IN(SELECT word FROM dictionary2);
样本数据:
CREATE TABLE `dictionary2` (
ID INT AUTO_INCREMENT PRIMARY KEY,
word VARCHAR (50),
verb VARCHAR (50)
);
CREATE TABLE `dictionary1` (
ID INT AUTO_INCREMENT PRIMARY KEY,
word VARCHAR (50)
);
INSERT INTO `dictionary2`(word,verb)
VALUES
('test','test'),
('test1','test1');
INSERT INTO `dictionary1`(word) VALUES('test'),('testing1');
顺便说一句,您可以安全地更改LIKE "t%"
为LIKE "w%"
;-)
SQL 小提琴演示