I am new to android development. I am developing a phonebook app. What I am doing is, trying to populate the phonebook with the contacts. Each contact has name, number and the emailId. Since each of the three is in a separate database, I am reading contact, phone and the Email db in that order. Based on the contactId I retrieve from the first read, I am querying the other two tables. However, the contactIds retreive from the contacts database does not match the ones in the phone and the email. My assumption is the Contacts._ID should be the key for all the three tables. Please let me know if I am doing something wrong here.
2 Answers
There should be some unique ID across the tables to identify related records (may not be contacts_id), it could be just ID from Contacts table.

- 65,990
- 13
- 130
- 167
When you say that you have separated DBs you mean different tables in the same database right? Anyway you need to use a so-called "foreign-key". I'm sure that if you google it you will find a lot of info
Assuming that you are using a relational database let's suppose you have a table T1 with a column that is the "primary key" (please google it too) let's say T1_PK. Let's suppose you have a second table T2 that references the first one like in your case the table with the email addresses for a given contact. In this second table you need a column like T1_FK that "points" to the raw in the T1 where the related contact is stored: this column will store the values that in T1 are in the column T1_PK.
You can use SQL and the JOIN keyword for the SELECT command to create a view (you can google it too with "relational database") that contains all the info in all the tables.

- 11,053
- 14
- 62
- 116
-
Thx Herschel. I took contact_id as the common column in contacts and the phone table... it solved my problem. – rahul Feb 08 '12 at 10:55