2012-02-21 4 views
1

테이블에있는 모든 질문을 추출하려고하는 쿼리가 있습니다.내 쿼리에서 매핑 테이블에 가입하는 방법

질문 게시물 주제 주제 매핑

내 태그 테이블이 주제 ID로 질문 ID를 매핑하기위한 제 3의 테이블로 설정되어 있습니다. 그러나

, 내가

그래서 기본적으로 내가 해달라고 JOIN를 문 주제 테이블에 저장된 항목의 이름을 당겨 어떻게 주제 ID를 가지고 오직 한 테이블에 가입 문을 수행하는 방법을 알고 없는 항목 이름은

SELECT questions.* 
    , posts.post 
    , COUNT(posts.post) as total_answers 
    , posts.votes 
    , posts.id as post_id 
    , posts.created 
    , users.id as user_id 
    , users.username, users.rep 
    , topics.name 
FROM questions 
LEFT JOIN posts ON questions.id = posts.question_id 
LEFT JOIN users ON questions.user_id = users.id 
LEFT JOIN topics ON topic_mapping.question_id = questions.id 
GROUP BY questions.id 

감사

먼저 매핑 테이블에 질문을 가입해야
+0

@northpole, 편집 해 주셔서 감사합니다! – youngcouple10

답변

5

많은에게.

SELECT questions.* 
    , posts.post 
    , COUNT(posts.post) as total_answers 
    , posts.votes 
    , posts.id as post_id 
    , posts.created 
    , users.id as user_id 
    , users.username, users.rep 
    , topics.name 
FROM questions 
LEFT JOIN posts ON questions.id = posts.question_id 
LEFT JOIN users ON questions.user_id = users.id 
LEFT JOIN topic_mapping ON questions.id = topic_mapping.question_id 
LEFT JOIN topics ON topic_mapping.topic_id = topics.id 
GROUP BY questions.id 
+0

Joe, 정말 고마워요 !!! 처음 일하면서 잘 지내라! – youngcouple10

관련 문제