I have a query result set that contains data that I need to filter, however, the filtering data is contained within another table and furthermore that filtering table is linked to another table that contains the groupings of filters. Even further the grouping table contains fields that may be null and I need to ignore these fields. I also need to group the results by the groups table. Any idea on the best approach to this problem?
STARTING DATA TABLE
MYID NAME ADDRESS AGE
1 FRED 123 SECOND ST 12
2 JILL 321 FIRST ST 6
3 JOE 54 THIRD ST 4
FILTERING TABLES
--Group: table that is keyed via xref to Set table
GROUP_ID AGEFROM AGETO MYID
1 3 7 NULL
2 NULL NULL 2
--Set: table that is xrefed to group table
SET_ID NAME
5 SET1
6 SET2
--Xref: table connecting Set and Group
SET_ID GROUP_ID
5 1
5 2
6 1
DESIRED OUTPUT BY QUERYING THE STARTING DATA TABLE USING THE FILTERING TABLES AS FILTERING CRITERIA
SET GROUP NAME AGE ID ADDRESS
5 1 JILL 6 NULL 321 FIRST ST
5 1 JOE 4 NULL 54 THIRD ST
5 2 JILL NULL 2 321 FIRST ST
6 1 JILL 6 NULL 321 FIRST ST
6 1 JOE 4 NULL 54 THIRD ST
To restate my need:
I need to output the results of the 1st table filtered by the Group Table content and then grouped by the set table taking into consideration possible nulls in the group table as well as ranges of data. Make sense?
What is the best approach to achieve this result?
Thank you for you input. I am a bit confused as to why my request is deemed incomplete and have negative marks on it… I provided the table example containing the data to be filtered, and then the other three tables that contain the filtering data. I even later provided the expected output. I am trying to get some assistance as to a direction to be able to filter/search the database and use the filtering database as the criteria to filter the data to the desired output. I figured there were great SQL folks here that could possible help me. I am a bit confused as to the responses
You need to use some joins, something like this:
Your question is not clear so I can’t say for sure this is an answer. Please take the following advices on using stackoverflow:
In general terms, you should review the FAQ and follow its guidelines very seriously. That way stackoverflow will be most useful to you and to others. https://stackoverflow.com/faq