SELECT
upd.*,
usr.username AS `username`,
usr.profile_picture AS `profile_picture`
,(
SELECT COUNT (like.id)
FROM likes as like
WHERE upd.update_id = like.item_id
AND like.uid = 118697835834
) as liked_update
FROM updates AS upd
LEFT JOIN users AS usr
ON upd.uid = usr.uid
WHERE upd.deleted=0
AND
( upd.uid=118697835834
OR EXISTS ( SELECT *
FROM subscribers AS sub
WHERE upd.uid = sub.suid
AND sub.uid = 118697835834
)
)
ORDER BY upd.date DESC
LIMIT 0, 15
SELECT
中的子查询返回以下错误:You have an error in your SQL syntax; check the manual that corresponds to your MySQL
server version for the right syntax to use near
'like WHERE upd.update_id = like.item_id AND l' at line 10
最佳答案
like
是SQL中的保留字;您应该为likes
表使用不同的别名。将子查询更改为:
SELECT
COUNT (like.id)
FROM
likes as like
WHERE
upd.update_id = like.item_id
AND like.uid = 118697835834
类似于:
SELECT
COUNT (l.id)
FROM
likes as l
WHERE
upd.update_id = l.item_id
AND l.uid = 118697835834