title: sqlite raw query with inner join and content provider failing to filter by WHERE clause
body: <p>I am using a content provider with a multi-table sqlite database. Some of the tables have a relationship to one another of one to many. One table lists the entities and the second table lists the activities, with a reference to the entity by way of the "foreign key" which is the ID of the entity. I don't use an actual "foreign key" but this is how I keep track.</p>
  
  <p>Here are my database tables:</p>
  
  <pre><code>private static final String CREATE_TABLE_ENTITY = "CREATE TABLE  " + TABLE_ENTITY +  "  ( " + ENTITY_KEY_ID + "  INTEGER PRIMARY KEY, " + NAME + " TEXT, " +  DATE_OBTAINED +  " TEXT, " +  PROFILE_IMAGE + " TEXT, " + QUALITY1 + " TEXT, "  + QUALITY2 +  " TEXT, " +  QUALITY3 + " TEXT, " + " )" ;
  
  private static final String CREATE_TABLE_ACTIVE_ENTITIES = "CREATE TABLE  " + TABLE_ACTIVE_ENTITIES + "  ( " +  ACTIVE_ENTITY_KEY_ID  + "  INTEGER PRIMARY KEY, " + TABLE_ENTITY_KEY_ID + " INTEGER, " + NAME  + " TEXT, " +  DATE  +  " TEXT, " + ACTIVITY1  + " TEXT, " +  ACTIVITY2  + " TEXT, "  + ACTIVITY3 + " TEXT, " + ACTIVITY4 +  ...  + "  )" ;
  </code></pre>
  
  <p>So I want to query the results of a particular Entity and get the most recent Activities.  I attempted an inner join on the ENTITY_KEY_ID which is equivalent to the TABLE_ENTITY_KEY_ID in the Activities Table.</p>
  
  <p>This is my content provider query:</p>
  
  <pre><code>@Nullable
  @Override
  public Cursor query(Uri uri, String[] strings, String selection, String[] selectionArgs, String sortOrder) {
        db = hdb.getWritableDatabase();
      int uriType = uriMatcher.match(uri);
       Cursor cursor = null
       case TABLE_ENTITY_JOIN_TABLE_ACTIVE_ENTITIES_ID:
              if (uri != null) {
                  String[] args = {uri.getLastPathSegment()
  
                  cursor = db.rawQuery("SELECT  table_entity.NAME, date_obtained, profile_image, quality1, quality2,  quality3, table_active_entities.activity1, table_active_entities.activity2 " +  " FROM table_entity, table_active_entities " + " ON ENTITY_KEY_ID = table_entity_key_id " + " WHERE ENTITY_KEY_ID=?", args);
              }
              break;
          default:
              throw new IllegalArgumentException("Unknown Uri");
      }
      if (cursor != null) {
          cursor.setNotificationUri(getContext().getContentResolver(), uri);
      }
      return cursor;
  }
  </code></pre>
  
  <p>This is where I call the query from my activity :</p>
  
  <pre><code> @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_hermit_page);
  
  
      getInfoIntent = getIntent();
  
      uri = getInfoIntent.getParcelableExtra(MyProvider.CONTENT_ITEM_TYPE);
  
      getSupportLoaderManager().initLoader(0,null,this);
  
      action = Intent.ACTION_ATTACH_DATA;
      EntityDataFilter = MyDatabaseHelper.ENTITY_KEY_ID + " = " + uri.getLastPathSegment();
  
      long id = Long.parseLong(uri.getLastPathSegment());
  
      Cursor cursor = getContentResolver().query(ContentUris.withAppendedId(MyProvider.CONTENT_URI_TABLE_ENTITY_JOIN_TABLE_ACTIVE_ENTITIES, id),null, null, null, null);
  
      if (cursor != null) {
          cursor.moveToFirst();
  
          name = cursor.getString(cursor.getColumnIndex(MyDatabaseHelper.NAME));
          hImage = cursor.getString(cursor.getColumnIndex(MyDatabaseHelper.PROFILE_IMAGE));
        ...
          cursor.close();
      }
  </code></pre>
  
  <p>The issue I am having is the WHERE clause which selects the ID is not pulling up the rows.  I am either getting the result of the first ID of the ENTITY table if I put cursor.moveToFirst() or I am getting the last ID of the ENTITY table if I put cursor.moveToLast().  I am not getting the info from the join only from the ENTITY TABLE.  It does not correlate to which ENTITY_ID is actually selected. So it seems the WHERE clause is not filtering by ID.  I tried adding parameters to the query statement within the activity(using the EntityDataFilter string) , but this did not produce any difference in results.  I also tried writing the select query as a string initially then plugging the string in the content provider query like : cursor.db.RawQuery(MyStringQuery,args) but this did not work either. I am tracking the output by looking at the TextView results in my activity. Your help is greatly appreciated if you understand why it is giving these results and how I can better write the statement to get the results that I want.  Thank you very much in advance!</p>