0
我的网站是Q &类似网站stackoverflow.com。当用户创建问题时,他有能力对其进行标记。之后,当他需要查找属于某个类别的所有问题时,他可以使用接受标签名称的过滤器框。根据用户的条目,我只会刷新工作列表。使用SQL应用过滤器加入
我的表设计是像下面
Table: Questions
id | QuestionTitle |Other details|
----------------------------------|-------------|
1 | Why is earth round? |
2 | How much is moon's diameter? |
Table: Tags
id | tagname
----------------
1 | planets
2 | earth
3 | moon
Table: AttachedTags
id | question_id | tag_id
-------------------------
1 | 1 |2
2 | 1 |1
3 | 2 |3
在PHP /控制器我会得到标签的ID作为用户输入的的过滤箱。
什么是在特定标签下获取所有这些问题的最佳方法?
我已经使用了下面的查询,但是它检索一个作业两次,因为作业可以有多个类别。
SELECT
Questions.id,
Questions.jobtitle,
AttachedTags.tag_id
FROM
Questions INNER JOIN
AttachedTags ON Questions.id = AttachedTags.question_id
WHERE
AttachedTags.tag_id IN (1,2)
我在AttachedTags表格的例子中看不到skill_id ... – 2014-12-07 11:46:45