title: What is the difference in contacts versus raw-contacts?
body: <p>I have a "dump" utility that I am using to study the ContactsContract since I don't quite get it in the documentation.  When I dump the contacts it counts 263 records in the table, however, the contacts application on my device lists that I have 244 ("Displaying 244 contacts.")</p>
  
  <p>Can someone explain the discrepancy?</p>
  
  <p>My Sprint LG's Contacts App has display options for each of the accounts that I sync and I have gone in and checked all of them, so there shouldn't be any filtering.</p>
  
  <p>The main URI that I am using in the utility is:</p>
  
  <pre><code>    Uri uriRawContacts = ContactsContract.RawContacts.CONTENT_URI;
      String[] projection = new String [] {
              ContactsContract.RawContactsEntity._ID,
              ContactsContract.RawContactsEntity.CONTACT_ID,
              ContactsContract.RawContactsEntity.DELETED,
              ContactsContract.RawContactsEntity.AGGREGATION_MODE,
      };
      Cursor cursorRaw = cr.query(uriRawContacts, projection, null, null, null);
      DumpCursor.dumpAnyCursor(getApplicationContext(), "RawContacts", cr, cursorRaw, ",");
  </code></pre>
  
  <p>Followed by (for each _ID in the above query):</p>
  
  <pre><code>                long rawContactId = Long.parseLong(anyCursor.getString(anyCursor.getColumnIndex(RawContacts.CONTACT_ID)));
  
                  Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId);
                   Uri entityUri = Uri.withAppendedPath(rawContactUri, Entity.CONTENT_DIRECTORY);
  
                   Log.d(TAG, "rawContactUri: " + rawContactUri.toString());
                   Log.d(TAG, "entityUri: " + entityUri.toString());
  
                   Cursor c = cr.query(entityUri, new String[] { RawContacts.SOURCE_ID, Entity.DATA_ID, Entity.MIMETYPE, Entity.DATA1 }, null, null, null);
  </code></pre>
  
  <p>I then loop through the first query, display all the columns in my projection, then, using the _ID field in the first query's loop, I issue the second query and dump all of its columns.</p>
  
  <p><strong>Bullets from the answer transposed here for convenience:</strong>
  <em>Refer to the reference for more detailed explanation.  More specifically, you are encouraged to read about the aggregation rules.</em>
  Ref: <a href="https://stackoverflow.com/questions/5151885/android-new-data-record-is-added-to-the-wrong-contact/5158059#5158059">Click here for the original cited text that follows</a></p>
  
  <blockquote>
    <ul>
    <li>The Contacts database is divided into    3 tables contacts, raw
    contacts, and    data.</li>
    <li>Each table contains column (_ID)    which is an auto incremented primary<br>
    key.</li>
    <li>The data table contains all the contact    info like phone number, mail id,<br>
    address etc.</li>
    <li>The raw contacts points to the actual    contact created. Hence we
    use the raw    contacts while adding a
    contact.</li>
    <li>The user cannot add any data in the    contacts table. The data in this<br>
    table is populated internally due to<br>
    aggregation of contacts.</li>
    </ul>
    
    <p>The reason your logic worked for some
    of the contacts is: _ID for contacts,
    raw contacts remains same until there
    is any contact aggregation taking
    place. Lets say you add two contacts
    with same name abc. Here the _ID for
    raw contacts increments twice while
    _ID for contacts increments only once as these two contacts gets merged due
    to the aggregation of contacts</p>
  </blockquote>