Union of Tables with Cursor in Android

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.

@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;

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?

Additionally, when I delete a row from the ListView, the cursor is not getting updated in spite of setNotificationUri()

Any pointers, will be most appreciated


Solved - I had to supply a group by clause as one of the columns (of the projection) had a "TOTAL(...)" function.


  • How can i use Regex to get data from sqlite?
  • How to access MISSED_CALL Log in Android
  • How can I select count(field) and still get an object with createQueryBuilder
  • Marklogic (Nodejs API) - Search documents that match 2 (or more) conditions in object array attribut
  • Doctrine2 get object without relations
  • Show list in groups
  • Print SQL query of ORM query builder in cakephp3
  • MATCH with selectArgs looking like *queryTerm* stopped working on Android 5.0+
  • MySQL Pivot Table Head Scratcher
  • SQliteQueryBuilder setDistinct does not include all unique values in Android Studio
  • How to use Doctrine's “is empty” within an Expression?
  • ORMLite query date format issue
  • How to show installer to the user
  • Union of Tables with Cursor in Android
  • Receiver has no segue with identifier
  • Sorting a table physically in Delphi
  • Render a treeview using a for-loop
  • Sorting a DataTable using LINQ, when sort-by-columns may vary
  • AVCaptureSession VS UIImagePickerController camera preview
  • if some function is not optimized does it mean that all functions where it is declared are not optim
  • How to concat Pandas dataframe columns
  • Group list of tuples by item
  • Hide HTML elements without javascript, only CSS
  • Get specific string
  • Copy to all folders batch file?
  • preg_replace Double Spaces to tab (\\t) at the beginning of a line
  • Moving mysql files across servers
  • Extracting HTML between tags
  • MongoDB in PHP using aggregate to group by _id is null not working
  • How to make a tree having multiple type of nodes and each node can have multiple child nodes in java
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • Linker errors when using intrinsic function via function pointer
  • Python: how to group similar lists together in a list of lists?
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • LevelDB C iterator
  • How can i traverse a binary tree from right to left in java?