To filter a table output of selected entries from a single table i would need something like a multiple JOIN request through several tables.
I want to filter a table of people by a special column in the table. Lets say this column is “tasks.” Now tasks is also another table with the column “people” and the values between those two tables are connected with an existant “join” table in the database, which is matching several IDs of one table to each ID of the other table.
Now if this would be simple as that i could just filter with an INNER JOIN and a special condition. The problem is, that the entries of the table “tasks” are connected to another table over a “join” table in the database. To simplify things lets say it is “settings”. So each “task” consists of several “settings” which are connected via a join table in their IDs.
So what is the input?
I got an array of IDs, which are representing the settings-ids i do not want to be shown.
What should be the output?
As already said i want a filtered output of “people” while the filter is “settings.”
I want the sql request to return each entry of the table “people” with only joined tasks that are not joining any of the “setting-ids” from the array.
I hope you can help me with that.
Thanks in advance!
Example
Settings-Table:
1. Is in progress
2. Is important
3. Has unsolved issuesTasks-Table: (settings.tasks is the join table between many tasks to many settings)
1. Task from 01.01.2012 – JOINS Settings in 1 and 3 (In progress + unsolved issues)
2. Task from 02.01.2012 – JOINS Settings in 2 (Is important)
3. Task from 03.01.2012 – JOINS Settings in 1 and 2 (…)People-Table: (people.tasks is the join table between many people to many tasks)
1. Guy – JOINS Tasks in 1, 2, 3 (Has been assigned to all 3 tasks)
2. Dude – JOINS Tasks in 1 (Has been assigned to the Task from 01.01.2012)
3. Girl – JOINS Tasks in 2, 3 (…)Now there is an array passed to a sql query
[2,3] should return noone because every person is assigned in a task that was either important or had unsolved issues!
[3] would return me only the person “Girl” because it is the only one that is assigned to tasks (2 and 3) that had no unsolved issues.
I hope it is clear now. 🙂
EDIT (for supplying multiple setting ids you don’t want)