현재 내 학교 프로젝트를위한 자체 포럼을 구축 중이며이 쿼리는 모든 포럼 카테고리를 나열하고 있지만 사용자가 읽지 않은 주제/스레드가 있는지 확인한 다음 포럼 카테고리에 읽지 않은 메시지가있는 것으로 태그를 지정하는 경우 문제가 있는지 확인하는 중입니다. .하위 쿼리에 알 수없는 열이 표시되는 이유는 무엇입니까?
그것은 하위 쿼리에서 "알 수없는 열이 '필드 목록'에서 'forum_category.id'"라고 ... 난 하위 쿼리에 몇 가지 예제를 확인하고 내가 본 것을에서 내가 액세스 할 수 있어야합니다 을 forum_category.id 하위 쿼리에서 사용합니까? 나는이 시점에서 무엇을 잘못하고 있는지 보지 못합니다 ...
도움을 많이 받으실 수 있습니다!
SELECT forum_category.id
, root.name AS root_name
, subcat.name AS subcat_name
, subcat.id AS subcat_id
, subcat.description AS subcat_description
, subcat.safe_url AS subcat_safe_url
, topics.topic_id
, topics.topic_safe_url
, topics.topic_title
, topics.last_post_time
, topics.topic_last_poster_name
, topics.topic_last_poster_id
, (
SELECT
posts_read.last_read_time
FROM
forum_topics a
LEFT JOIN
forum_posts_read AS posts_read ON
posts_read.last_read_time > a.last_post_time
AND posts_read.last_read_time >04546
AND posts_read.topic_id = a.topic_id
AND posts_read.user_id = 1
AND a.forum_id = forum_category.id
LIMIT 1) AS last_read_time
FROM forum_category AS root
LEFT JOIN
forum_category AS subcat ON subcat.parent_id = root.id
LEFT JOIN
forum_topics AS topics ON topics.forum_id = subcat.id
LEFT JOIN
forum_topics AS t2 ON t2.forum_id = subcat.id AND t2.last_post_time > topics.last_post_time
WHERE
root.parent_id = 0 AND t2.forum_id IS NULL
ORDER BY
root_name, subcat_name
나는이 시도 알고하지만 각 카테고리에서 첫 번째 항목/스레드를 확인
... 생각을했다SELECT root.name AS root_name
, subcat.name AS subcat_name
, subcat.id AS subcat_id
, subcat.description AS subcat_description
, subcat.safe_url AS subcat_safe_url
, topics.topic_id
, topics.topic_safe_url
, topics.topic_title
, topics.last_post_time
, topics.topic_last_poster_name
, topics.topic_last_poster_id
, posts_read.last_read_time
FROM forum_category AS root
LEFT JOIN
forum_category AS subcat ON subcat.parent_id = root.id
LEFT JOIN
forum_topics AS topics ON topics.forum_id = subcat.id
LEFT JOIN
forum_topics AS t2 ON t2.forum_id = subcat.id AND t2.last_post_time > topics.last_post_time
LEFT JOIN
forum_posts_read AS posts_read ON
posts_read.last_read_time > topics.last_post_time
AND posts_read.last_read_time > ?
AND posts_read.topic_id = topics.topic_id
AND posts_read.user_id = ?
AND topics.forum_id = subcat.id
WHERE
root.parent_id = 0 AND t2.forum_id IS NULL
ORDER BY
root_name, subcat_name
는이 하드 ... 나는 그것보다는 의미하는 것 간단한 일을하고 싶습니다 : (
는 ROOT의 시도로 forum_category 별명했습니다 때문입니다'와 a.forum_id = Root.id' – xQbert