samedi 25 juillet 2015

SQLite: Select all Names of given Colors

I have an SQLite Database, two of the tables look like this:

ID    Name
1     Test1
2     Test2
3     Test3
4     Test4

ID    Color
1     Blue
1     White
1     Red
2     Green
2     Red
4     Black

In the first Tables, ID is unique, the second table lists colors an ID has, it can be from 0 to n colors.

Now I want to select all Names exactly once, that have one or more given color. Lets say, I want to have all names associated with blue, white and/or green. The resultset should have the IDs 1 and 2.

I am completly lost here, as I normally dont do any SQL. I am just familiar with very basic SQL. What I would do is Join the tables together, but I dont know how I do that, as ID is not unique in the second table. Also there would be the problem of IDs beeing duplicated in the resultset, if it has multiple colors that I want to select.

Thanks in advance for any help.

Aucun commentaire:

Enregistrer un commentaire