On 21 May 2014, at 1:59pm, fantasia dosa <[email protected]> wrote:
> TeamTable -
> parId: 4
> personIDs : 1,5,9,6
>
> PersonTable -
> id:
> name:
>
> SELECT * FROM PersonTable WHERE id IN (SELECT personIDs FROM
> PersonTable WHERE parId = 4);
Your problem is cause by the way you're keeping your data. I would like to
suggest a better way, which is often called 'normal form' by people who use
SQL. There are two possibilities:
A) Each person is in either zero or one team: Remove 'personIDs'; add a
'teamID' column to your PersonTable. If you have a person who is currently not
in any team, set the column to 0.
B) Each person can be in more than one team: Remove 'personIDs'; create a new
table 'PeopleInTeamsTable' which has two columns: teamID and personID.
Doing either of these will give you a simple SELECT command to select people
details. You will probably end up using JOIN something like this:
SELECT PersonTable.* FROM PersonTable
JOIN TeamTable ON PersonTable.teamID = TeamTable.id
WHERE TeamTable.parId = 4
Simon.
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users