INSERT INTO `dictionary2` (word,verb)
SELECT SUBSTRING(word FROM 2)
FROM `dictionary1`
WHERE `dictionary1`.word LIKE "w%"
我有两个表,dictionary1(word)和dictionary2(word,动词)。
答案 0 :(得分:1)
你可以用这个:
INSERT INTO dictionary2 (word, verb)
SELECT dictionary1.word, 1
FROM
dictionary1 LEFT JOIN dictionary2
ON dictionary1.word = dictionary2.word
WHERE
dictionary1.word LIKE 'w%'
AND dictionary2.word IS NULL
请参阅小提琴here。
答案 1 :(得分:0)
试试这个:
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');
B.T.W。您可以安全地将LIKE "t%"
更改为LIKE "w%"
; - )