简体   繁体   English

建立一个SQL“ toxi”标签系统,如何选择带有特定标签的项目?

[英]Building a SQL “toxi” tagging system, how to select items with a specific tag?

First of all, i'm new to sql. 首先,我是sql的新手。

Now, I'm building a tagging system with sqlite for my android app that uses 3 tables (items, tags, tagmap) based on this "toxi" solution found here , but I'm not sure on how the mechanics work, how would I select all items from this itemsTable that have a specific tag. 现在,我正在为我的android应用构建带有sqlite的标签系统,该标签系统基于此处找到的“ toxi”解决方案使用3个表(项目,标签,标签图),但是我不确定其工作原理,操作方式我从这个itemsTable中选择所有具有特定标签的项目。

itemsTable 项目表

itemid 项目编号

2 2

3 3

4 4

tagsTable 标签表

tagid tag tagid标签

2 "ruby" 2“红宝石”

3 "java" 3个“ java”

7 "c" 7“ c”

tagmap 标签图

itemid tagid itemid tagid

2 3 2 3

3 7 3 7

2 2 2 2

4 7 4 7

I was trying something along the lines of: 我正在尝试以下方法:

SELECT* FROM itemsTable INNER JOIN tagmap ON tagmap.itemid= itemsTable.itemid AND tagmap.tagid=tagsTable.tagid WHERE tagsTable.tagid= desiredid

But this seems to be wrong. 但这似乎是错误的。

BTW: all itemid and tagsid are primary keys auto-incremented 顺便说一句:所有itemid和tagid是自动递增的主键

Any answers or an alternative to creating a tagging system(in which an item can have more than one tag) are welcomed. 欢迎创建标签系统(其中一个项目可以具有多个标签)的任何答案或替代方法。

Your query is wrong. 您的查询是错误的。 You did not include the "tagsTable" in your join. 您没有在联接中包括“ tagsTable”。 Try this: 尝试这个:

SELECT* FROM itemsTable INNER JOIN tagmap ON tagmap.itemid= itemsTab 
INNER JOIN tagsTable ON tagmap.tagid=tagsTable.tagid WHERE tagsTable.tagid= desiredID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM