我试图从我的表中选择一些值,但它返回0行。如果我评论其中一个条款 - 它可以工作,但是当我添加“和”时它不会。
这是我的代码
cursor = mValtoneDB.mDataBase.rawQuery("select activity.name as name, activity._id as id " +
"from activity inner join discipline " +
"on discipline._id = activity.disciplineId " +
"inner join user_discipline_lt " +
"on discipline._id = user_discipline_lt.disciplineId "
+ "where" +
" user_discipline_lt.userId=? " +
"and" +
" discipline._id=?"
, new String[] { Integer.toString(userId), Integer.toString(disciplineId) }
我不知道该怎么做:\
随着db随机填充我记录了很多(输出太多)这里有关于id 3的纪律的一切:
01-05 04:39:38.330 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 1
01-05 04:39:38.330 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 2
01-05 04:39:38.330 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 5
01-05 04:39:38.330 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 6
01-05 04:39:38.330 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 7
01-05 04:39:38.335 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 9
01-05 04:39:38.335 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 10
01-05 04:39:38.335 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 16
01-05 04:39:38.335 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 18
01-05 04:39:38.335 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 19
01-05 04:39:38.335 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 20
01-05 04:39:38.335 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 22
01-05 04:39:38.335 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 23
01-05 04:39:38.335 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 24
01-05 04:39:38.335 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 1
01-05 04:39:38.335 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 2
01-05 04:39:38.335 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 5
01-05 04:39:38.335 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 6
01-05 04:39:38.335 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 7
01-05 04:39:38.335 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 9
01-05 04:39:38.335 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 10
01-05 04:39:38.335 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 16
01-05 04:39:38.340 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 18
01-05 04:39:38.340 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 19
01-05 04:39:38.340 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 20
01-05 04:39:38.340 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 22
01-05 04:39:38.340 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 23
01-05 04:39:38.340 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 24
01-05 04:39:38.340 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 1
01-05 04:39:38.340 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 2
01-05 04:39:38.340 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 5
01-05 04:39:38.340 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 6
01-05 04:39:38.340 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 7
01-05 04:39:38.340 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 9
01-05 04:39:38.340 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 10
01-05 04:39:38.340 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 16
01-05 04:39:38.340 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 18
01-05 04:39:38.340 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 19
01-05 04:39:38.340 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 20
01-05 04:39:38.345 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 22
01-05 04:39:38.345 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 23
01-05 04:39:38.345 1836-1836/cullycross.cursed D/cursors info:﹕ discipline id 3 user id 24
答案 0 :(得分:0)
您的SQL语法是正确的。删除“and”子句并观察结果。检查您的discipline._id是否符合预期,至少有一行。