I am trying to extract data from many tables. I apologize if this explanation is fuzzy, but this is the best I can do without a detailed explanation of all the internal workings of my program.
I have 2 modules in the application.
The first module displays information related to a group of elements.
And it removes information that is absent in all elements. (lowest common denominator)
So...
The first item is red and green.
The second item is green and blue.
And point three is only green.
Thus, the table will be a list of elements, and the second table will be a list of colors.
And of course, the third table contains relationships.
I am trying to get the module to display only the elements from table 2 that are present in all elements from the first.
In this case, this will cause the displayed items to be simply green, because this is the only common item.
I tried to do this programmatically, and it was a nightmare to watch and debug. This will be a mobile application, so all for loops will lag far behind my program. I know there must be a way to do this using SQL, but after hours of research, I still can't wrap myself around it.
Thanks.
UPDATE for clarity:
Ok, I made 2 mistakes in my question. Firstly, I am not looking for a total, I am looking for a total VALUE. Therefore, I want only the colors that exist in all three elements, and abandon the rest. Secondly, I had to be more specific. I am developing an application for Android phones, so I use Java and SQLite.
Here is what I have so far in the original form, and not in the color example that I used. This code tag will have the same color and the other will be equal to the element ...
SELECT DISTINCT tag.name
FROM other_tag_relationship AS otr
JOIN tag ON otr.tag_id = tag._id
WHERE otr.other_id in (2, 3, 4);
This explicitly returns a separate list of all tags for all others.
Now I want to show only those tags that are available in ALL others, and abandon the rest. How to remove any tags from 2 that are also not in 3 and 4. In addition, a list (2, 3, 4) will be generated dynamically at run time.
Thanks again.