This query returns ONLY the primary records who filled out the question 11042 and answered “Yes”. Fine great no prob. But This primary may possibly have group members assigned under them that may also need to pull into this search query. HOWEVER they do not answer the question 11042 so arent in the fields t2 table. They are however in another table grpMems t3, lets say, which is also joined on id. So my question is how do i display both, primarys who answered the question yes and are thus in the t2 table, AND the group members who are in another t3 table for the search results?
select t1.id,t1.firstname,t1.lastname,t2.field1,t2.field2
from names t1
inner join fields t2 on t1.id=t2.id and t2.field1=2388 and t2.field2=11042 and t2.field3='Yes'
where 1=1
<cfif searchby>
and t1.firstname like '%#searchFIRST#%'
</cfif>
order by t1.lastname,t1.firstname
Using two left joins and requiring a minimum of one of them to have data:
If any of these relationships are many-to-many, you will need to do something to weed out duplicates though.
Using a union:
Again if you have duplicates you will either need to use a
UNIONto weed them out or do something else.