INSERT INTO Odds_display (Team, Odds)
SELECT DISTINCT Team1, Odds1
FROM Odds
WHERE Team1 = 'Team SoloMid'
AND NOT EXISTS (SELECT Team FROM Odds_display)
所以,我不知道我是盲目还是愚蠢...或者两者兼而有之! SQL的初学者,但我的目标是从表中复制2个值并将它们插入到另一个表中,但不要插入任何重复项!
所以表格Odds是"original"
表,我想复制到Odds_display
表并防止重复!
答案 0 :(得分:0)
您的子查询中需要WHERE
子句来告诉您哪个团队不想创建
INSERT INTO Odds_display (Team, Odds)
SELECT DISTINCT Team1, Odds1
FROM Odds
WHERE Team1 = 'Team SoloMid'
AND NOT EXISTS (SELECT * FROM Odds_display WHERE Team = 'Team SoloMid')
答案 1 :(得分:0)
尝试将NOT EXISTS
更改为NOT IN
,如下所示
INSERT INTO Odds_display (Team, Odds)
SELECT DISTINCT Team1, Odds1
FROM Odds
WHERE Team1 = 'Team SoloMid'
AND Team1 NOT IN (SELECT Team FROM Odds_display)