这是对SQL语句的查询
UPDATE TrendingEvents
SET Name = ?, Image = ?, Date = ?, EventCategory = ?
WHERE ID = ?;')
我想访问我的TrendingEvents表中另一个表的ID。这是我做过的示例,尽管它不能完全起作用;
UPDATE TrendingEvents INNER JOIN
Events AS eID
ON TrendingEvents.ID = Events.ID
SET Name = ?, Image = ?, Date = ?, EventCategory = ?
WHERE eID = ?;')
我想使用事件表中的ID列更新TrendingEvents表。
我从陈述中得到的错误是
Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'Name'
这只是表明我对查询的设计不佳。
答案 0 :(得分:1)
两个表似乎都包含一个名为Name的列。您需要使用表名正确为字段加上前缀,例如:
UPDATE
TrendingEvents AS t
INNER JOIN Events AS e
ON t.ID = e.ID
SET
t.Name = ?,
t.Image = ?,
t.Date = ?,
t.EventCategory = ?
WHERE e.eID = ?
答案 1 :(得分:0)
您滥用了表别名,因此您的查询甚至不应编译。试试这个:
UPDATE TrendingEvents te INNER JOIN
Events e
ON te.ID = e.ID
SET te.Name = ?,
te.Image = ?,
te.Date = ?,
te.EventCategory = ?
WHERE e.eID = ?;