I have written a query that is supposed to find which pupils have logged into the app in the current week. my SQLite query looks like this:
public static final String WHOLE_QUERY = "SELECT " + DBHelperTest.USER_ID
+ " , " + DBHelperTest.FNAME + " , " + DBHelperTest.SNAME
+ " FROM " + DBHelperTest.TABLE_CHILD + " WHERE "
+ DBHelperTest.USER_ID + " = (SELECT " + DBHelperTest.USER_ID
+ " FROM " + DBHelperTest.TABLE_SESSION_DATA + " WHERE "
+ DBHelperTest.WEEK_OF_YEAR_SIGNED_IN + " = " + theWeek() + " AND "
+ DBHelperTest.YEAR_SIGNED_IN + " = " + theYear() + ") " + " AND "
+ DBHelperTest.USER_ID + " = (" + "SELECT "
+ DBHelperTest.Child_USER_ID + " FROM " + DBHelperTest.TABLE_CLASS
+ " WHERE " + DBHelperTest.Teacher_USER_ID + " = (SELECT "
+ DBHelperTest.USER_ID + " FROM " + DBHelperTest.TABLE_SESSION_DATA
+ " WHERE " + DBHelperTest.SESSION_ID + " = ( SELECT MAX("
+ DBHelperTest.SESSION_ID + ") FROM "
+ DBHelperTest.TABLE_SESSION_DATA + ")))";
It returns nothing. However If I split it into two queries...
firstly this query shows all the users logged in this week:
public static final String LOGGED_IN_THIS_WEEK_QUERY = "SELECT "
+ DBHelperTest.USER_ID + " , " + DBHelperTest.FNAME + " , "
+ DBHelperTest.SNAME + " FROM " + DBHelperTest.TABLE_CHILD
+ " WHERE " + DBHelperTest.USER_ID + " = (SELECT "
+ DBHelperTest.USER_ID + " FROM " + DBHelperTest.TABLE_SESSION_DATA
+ " WHERE " + DBHelperTest.WEEK_OF_YEAR_SIGNED_IN + " = "
+ theWeek() + " AND " + DBHelperTest.YEAR_SIGNED_IN + " = "
+ theYear() + ") ";
this query outputs the user with userId "Jasm".
secondly this query shows all the users associated with the given teacher:
public static final String CHILD_WITH_SAME_TEACHER_QUERY = "SELECT "
+ DBHelperTest.Child_USER_ID + " FROM " + DBHelperTest.TABLE_CLASS
+ " WHERE " + DBHelperTest.Teacher_USER_ID + " = (SELECT "
+ DBHelperTest.USER_ID + " FROM " + DBHelperTest.TABLE_SESSION_DATA
+ " WHERE " + DBHelperTest.SESSION_ID + " = ( SELECT MAX("
+ DBHelperTest.SESSION_ID + ") FROM "
+ DBHelperTest.TABLE_SESSION_DATA + "))";
this query outputs users with userId's "Jasm" and "thup".
why does my original query not output the details of "Jasm" as this user meets both criteria?
Aucun commentaire:
Enregistrer un commentaire