Need help to INNER JOIN multiple tables and use last value row in MySQL -
i have 3 tables follow:
comments
|id| |uid| |tid|
tracks
|id| |uid|
notifications
|id| |from| |tox|
how can update notifications
, set tox
equal tracks.uid
of relative tracks.id
equal last comments.tid
value?
i tried without success:
update notifications set tox = ( select uid tracks inner join comments on tracks.id = comments.tid order comments.tid desc limit 1 comments.tid=tracks.id) tox = 0 order id desc limit 1;
update
first edit , moved order by
@ end suggested. after got different error 1052 - column 'typeid' in field list ambiguous
.
i solved like:
update `notifications` set `tox` = ( select tracks.uid `tracks` inner join `comments` on tracks.id = comments.tid order comments.id desc limit 1) `tox` = 0 order `id` desc limit 1;
i think problem syntax of subquery:
update notifications set tox = (select uid tracks inner join comments on tracks.id = comments.tid comments.tid=tracks.id order comments.tid desc limit 1 ) tox = 0 order id desc limit 1;
the order by
goes after where
.
Comments
Post a Comment