Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SQLite从3个表中获取使用组合的对象列表_Java_Android_Mysql_Sqlite - Fatal编程技术网

Java SQLite从3个表中获取使用组合的对象列表

Java SQLite从3个表中获取使用组合的对象列表,java,android,mysql,sqlite,Java,Android,Mysql,Sqlite,我的sqlite数据库中有三个表 Categories: category_id, title Words: word_id, title, belongs_to(foreign key, category_id) WordImgs: wordImg_id, title, belongs_to(foreign key, words_id) 我正在尝试实现一个方法List getAllCategories。每个类别包含一个单词列表,每个单词包含一个单词图像列表 我用它来连接表,但是因为有多个值与

我的sqlite数据库中有三个表

Categories: category_id, title
Words: word_id, title, belongs_to(foreign key, category_id)
WordImgs: wordImg_id, title, belongs_to(foreign key, words_id)
我正在尝试实现一个方法List getAllCategories。每个类别包含一个单词列表,每个单词包含一个单词图像列表

我用它来连接表,但是因为有多个值与单个值相关,所以我得到了重复的值

SELECT categories.title, words.title, wordings.title
FROM categories
JOIN words on categories.id = words.belongs_to
JOIN wordImgs words.id = WordImgs.belongs_to
这个声明可能会返回

Category,Word,wordImg
_______________    
Animal Dog Dog1
Animal Dog Dog2
Animal Cat Cat1
如何导航光标,使列表中每个不同的类别和单词只选一个

编辑:考虑使用三个嵌套游标。我还没有在网上看到过这么多,有没有更好的选择?

试试这个查询

SELECT 
categories.title as categories_title, 
words.title as words_title, 
wordings.title as wordings_title
FROM categories
JOIN words ON categories.id=words.belongs_to
JOIN wordimgs ON words.id=WordImgs.belongs_to
在所有三个表中都有相同的列名,因此最好每个表都有别名


如果您需要从三个表中获取数据,请更好地使用JOIN将为您提供适当的数据

我建议您使用ORM库,而不是自己编写查询。我在android项目中使用了SugarORM,看看这个链接。

我不确定创建表后该怎么办,因为我必须先为每个类别创建一个单词列表。你有什么想法吗?你将从这个查询中得到一个数据数组,在for循环中迭代以显示单词列表,这就是你要寻找的吗?我想从categories表中的每一行创建一个类别,而不是重复的类别。每个类别都有自己的单词列表,我也需要从查询中创建这些单词。请查看此链接:Parse意味着您希望创建自己的数据结构,并在以后使用它进行操作。什么数据结构?你需要它做什么?@CL。我正在尝试获取一个类别的数组列表,我需要将其传递到我的主要活动中。可能解析不是正确的术语。请避免链接到外部存储库。在这里输入你的密码。