android - SQLite 查询没有按预期工作

标签 android sqlite

我对 SQLite 查询有疑问,无法解决。这些是我的 table :

CREATE TABLE Exercise 
(
 e_id int auto_increment primary key, 
 name varchar(20)
);

CREATE TABLE PersonalList 
(
 p_id int auto_increment primary key, 
 name varchar(20)
);

CREATE TABLE Exercise_Personal_List 
(
 e_id_m int auto_increment primary key, 
 p_id_m int
);


INSERT INTO Exercise
(e_id, name)
VALUES
('1', 'exercise1'),
('2', 'exercise2'),
('3', 'exercise3'),
('4', 'exercise4'),
('5', 'exercise5'),
('6', 'exercise6');

INSERT INTO PersonalList
(p_id, name)
VALUES
('1', 'list1'),
('2', 'list2'),
('3', 'list3');

INSERT INTO Exercise_Personal_List
(e_id_m, p_id_m)
VALUES
('2', '1'),
('4', '1'),
('6', '1'),
('1', '2');
  • 练习表:一组练习
  • PersonalList表:列表的集合
  • Exercise_Personal_List:对哪个 Exercise 是哪个 Exercise_Personal_List 的一部分的引用

我正在尝试获取尚未添加到特定列表的练习列表。例如。未添加到列表 1 中的那些。我的查询:

select * from Exercise 
where e_id not in ( 
    select e_id from Exercise_Personal_List
    where p_id_m like '1'
)

结果为空。我没有在查询中看到错误。正确的结果应该是 1, 3, 5。

顺便说一句,我正在使用 http://sqlfiddle.com来评价这个东西。测试速度更快:)

感谢您的帮助!

最佳答案

我认为您的意思是执行以下查询,其中 e_id 的第二个实例已更改为 e_id_m:

select * from Exercise 
where e_id not in ( 
    select e_id_m from Exercise_Personal_List
    where p_id_m like '1'
)

关于android - SQLite 查询没有按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24918326/

相关文章:

安卓 : Getting "Cannot reload AVD list:" error at the time of execution

android - APK LICENSE 中复制的重复文件(同一文件)

iphone - 应用程序中的条形码识别

android - 如何保护android数据库文件?

database - 我的 Win JS SQLite 3 应用程序需要太多时间来进行插入

objective-c - 值插入模拟器但未显示在数据库表中

java - Android 开发 SQLite 与 Hashtable

android - Activity 开始时在 Android 中自动拉动刷新

sql - 如何在启用 FTS3 的情况下将二进制数据存储在 SQLite 表中?

ios - 如何在 sqlite iOS 中查找现有文件夹名称