I have 2 tables. One table contains a person’s name and that person’s unique ID. The other table has multiple columns, but there is one column in particular that stores the person’s unique ID.
Until now, the 2nd table has always stored a single ID, so I was able to easily perform JOINs on these two tables and get the data I needed like so:
SELECT DISTINCT personTable._id, personTable.name FROM dataTable LEFT OUTER JOIN personTable ON dataTable.person_id = personTable._id
However, a new requirement came into play that now will allow the 2nd table to reference more than one ID in the same column. In other words, the table used to be strictly like this:
2ND TABLE COLUMN PERSON'S ID = 5
But now the storage can be like this
2ND TABLE COLUMN PERSON'S ID = 5-6
2ND TABLE COLUMN PERSON'S ID = 5-3-8-2
2ND TABLE COLUMN PERSON'S ID = 5 (still valid)
With this new format, I can not query data successfully each time. How can I update this query to work properly? I am using SQLite in Android. Thanks for any help.
You will not get far if you use new format.
To serve new spec, you should change your schema to have one more table which will serve as join table.
In total, you will have 3 tables, something like this:
Jointable will have as many rows per user as you need, for example for
2ND TABLE COLUMN PERSON’S ID = 5-3-8-2
it will have 4 rows.
Now, you can have your data as follows: