我尝试编写php文件以将数据插入到我的数据库中。但我得到了错误。
此类型的子句先前已被解析。 (位置233处的“FROM”附近) 无法识别的语句类型。 (位置233处的“FROM”附近)
这是代码
INSERT INTO Game(date,teamone_id,teamtwo_id) SELECT
'$array[4]',
tid
FROM Team
WHERE teamName='$array[2]'
OR teamName='$array[3]',
tid
FROM Team
WHERE teamName='$array[2]'
OR teamName='$array[3]'
答案 0 :(得分:0)
您不能拥有多个WHERE
条款。看起来你正试图获得一个交叉产品,你需要使用自我加入。
INSERT INTO Game (date, teamone, teamtwo)
SELECT '$array[4]', t1.tid, t2.tid
FROM Team AS t1
CROSS JOIN Team AS t2
WHERE t1.teamName = '$array[2]'
AND t2.teamName = '$array[3]'
AND NOT EXISTS (
SELECT 1
FROM Game AS g
JOIN Team AS t1 ON t1.tid = g.teamtwo
JOIN Team AS t2 ON t2.tid = g.teamone
WHERE t1.teamName = '$array[2]'
AND t2.teamName = '$array[3]'
AND g.date = '$array[4]'
)
NOT EXISTS
检查现有行,并且团队ID已反转。