Note that there are some explanatory texts on larger screens.

plurals
  1. POSQLite, Tables, Joining
    primarykey
    data
    text
    <p>Android, implementing SQLite</p> <p>These are the tables i have:</p> <p><a href="http://postimg.org/image/jafsx39h7/" rel="nofollow">http://postimg.org/image/jafsx39h7/</a></p> <p>I have the code:</p> <pre><code>public String getWorkoutNameInfo() { // TODO Auto-generated method stub String[] columns = new String[] { KEY_DATE_OF_WORKOUT, KEY_WORKOUT_NAME, KEY_DATE }; Cursor c = ourDatabase.query(TABLE_DATE_WORKOUT, columns, null, null, null, null, null, null); String workoutName2 = ""; int iWorkoutID = c.getColumnIndex(KEY_WORKOUT_NAME); for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) { workoutName2 = workoutName2 + c.getString(iWorkoutID); } return workoutName2; } </code></pre> <p>This returns workoutName2 which is '2 1 2' </p> <p>Now i need to look up the value for 2 in my WorkoutTable and return 'Back' and produce 'Back,Chest,Back' so i can out put that onto my screen instead of 2 1 2. </p> <p>I understand I'll be using a JOIN statement? However i'm having no luck implementing it.</p> <p>My Table Coding:</p> <pre><code>// WORKOUT TABLE - COLUMN NAMES public static final String KEY_WORKOUT = "workout_id"; public static final String STRING_WORKOUT = "workout_name"; // DATE OF WORKOUT TABLE - COLUMN NAMES public static final String KEY_DATE_OF_WORKOUT = "date_of_workout_id"; public static final String KEY_DATE = "date_of_workout"; public static final String KEY_WORKOUT_NAME = "workout_id"; //TABLE NAMES private static final String TABLE_WORKOUT = "WorkoutTable"; private static final String TABLE_DATE_WORKOUT = "DateofWorkout"; </code></pre> <p>Here is my attempt: </p> <pre><code>public String test(String workoutSelectedNameInfo) { // TODO Auto-generated method stub String NAMEofWorkout = ""; open(); ourDatabase = ourhelper.getReadableDatabase(); Cursor c = ourDatabase .rawQuery( "SELECT * FROM WorkoutTable LEFT JOIN DateofWorkout ON (WorkoutTable.workout_id = DateofWorkout.workout_id) WHERE workout_id = ?", new String[] { "2" }); int iDateofWorkoutsWorkoutId = c.getColumnIndex(KEY_WORKOUT_NAME); for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) { NAMEofWorkout = NAMEofWorkout + c.getString(iDateofWorkoutsWorkoutId); } c.close(); ourDatabase.close(); System.out.println(NAMEofWorkout); return NAMEofWorkout; } </code></pre> <p>HOWEVER When it output the 'NameofWorkout' which SHOULD be Chest,Back,Chest i receive nothing at all, absolutely blank. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload