我有3张表如下:
评论
|id| |uid| |tid|
:跟踪
|id| |uid|
通知
|id| |from| |tox|
我UPDATE notifications
和SET tox
如何等于其相对tracks.uid
的{{1}}等于上一个tracks.id
值?
我尝试了这个没有成功:
comments.tid
更新
首先,我按照建议编辑并移动UPDATE notifications SET tox = (
SELECT uid FROM tracks
INNER JOIN comments ON tracks.id = comments.tid ORDER BY comments.tid DESC LIMIT 1
WHERE comments.tid=tracks.id)
WHERE tox = 0 ORDER BY id DESC LIMIT 1;
。之后我得到了一个不同的错误ORDER BY
。
我解决了它:
1052 - Column 'typeid' in field list is ambiguous
答案 0 :(得分:1)
我认为你的问题是子查询的语法:
UPDATE notifications
SET tox = (SELECT uid
FROM tracks INNER JOIN
comments
ON tracks.id = comments.tid
WHERE comments.tid=tracks.id
ORDER BY comments.tid DESC
LIMIT 1
)
WHERE tox = 0
ORDER BY id DESC
LIMIT 1;
ORDER BY
始终在WHERE
之后。