title: Union of Tables with Cursor in Android
body: <p>I am trying to UNION two tables with the same fields to create a single cursor (through a content provider) that I am using to create my ListView. </p>
  
  <pre><code>@Override
   public Cursor query(Uri uri, String[] projection, String selection,
     String[] selectionArgs, String sortOrder) {
  
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    String groupBy = null;
  
    switch (sUriMatcher.match(uri)) {
  
    case LIST:
     StringBuilder sb = new StringBuilder();
  
     for (String s : projection)
      sb.append(s).append(",");
  
     String projectionStr = sb.toString();
     projectionStr = projectionStr.substring(0,
       projectionStr.length() - 1);
  
     String[] subQueries = new String[] {
       "SELECT " + projectionStr + " FROM " + Customer.TABLE_NAME,
       "SELECT " + projectionStr + " FROM "
         + IndividualCustomer.TABLE_NAME };
     String sql = qb.buildUnionQuery(subQueries, sortOrder, null);
     SQLiteDatabase db = mDatabaseHelper.getReadableDatabase();
     Cursor mCursor = db.rawQuery(sql, null);
  
     mCursor.setNotificationUri(getContext().getContentResolver(), uri);
  
     return mCursor;
  </code></pre>
  
  <p>Even if the two tables are empty, I get two null rows, which creates two rows in my listview. How do I get rid of this problem?</p>
  
  <p>Additionally, when I delete a row from the ListView, the cursor is not getting updated in spite of setNotificationUri()</p>
  
  <p>Any pointers, will be most appreciated</p>