[英]Multiple joins with ordered by count ignores where conditions
I am trying to only get rows from video_index that belongs to a specific category from category_video_rel and order the result by COUNT of view count. 我正在尝试仅从video_index获取属于category_video_rel特定类别的行,并按COUNT个观看次数对结果进行排序。 This is the query I'm using:
这是我正在使用的查询:
SELECT COUNT(DISTINCT view_count.id) AS count, view_count.remove, view_count.video_id, video_index.id AS video_id, video_index.active, video_index.remove, video_index.title AS title, video_index.date_published AS date_published, category_video_rel.active, category_video_rel.remove, category_video_rel.video_id AS cv_video_id, category_video_rel.category_id AS category_id FROM view_count JOIN video_index ON view_count.video_id = video_index.id, category_video_rel JOIN video_index AS v ON category_video_rel.video_id = v.id WHERE view_count.remove = '0' AND video_index.active = '1' AND video_index.remove = '0' AND video_index.date_published <= '$current_time' AND category_video_rel.category_id = '$category_id' AND category_video_rel.active = '1' AND category_video_rel.remove = '0' GROUP BY video_index.id ORDER BY count DESC
The problem is it outputs all the rows from video_index with a view count higher than 0 regardless of the category. 问题在于,无论类别如何,它都会从video_index输出视图计数高于0的所有行。 Basically, it's ignoring "category_video_rel.category_id = '$category_id'" in the WHERE condition.
基本上,在WHERE条件下,它会忽略“ category_video_rel.category_id ='$ category_id'”。
I have no idea what I'm doing wrong, please help. 我不知道我在做什么错,请帮忙。
Your FROM
clause is mixing old style joins and new style joins Instead try: 您的
FROM
子句混合了旧样式的连接和新样式的连接,请尝试:
FROM
view_count JOIN video_index
ON view_count.video_id = video_index.id
JOIN category_video_rel
ON category_video_rel.video_id = video_index.id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.