Table 'people'
columns 'username','customfield','customvalue'
Table 'custom-fields'
columns 'fieldID','fieldName'
Data in 'people' table
joe, 2,small
joe,3,black
joe,4,deaf
pat,2,small
pat,3,brown
pat,4,blind
lisa,2,big
lisa,4,blind
alex,2,medium
alex,3,white
alex,4,deaf
Data in 'customfields' table
1,gender
2,size
3,color
4,handicap
I want to get a subset that finds all people who have the handicap of being 'blind' and returns all data about them
ie
pat,2,small
pat,3,brown
pat,4,blind
lisa,2,big
lisa,4,blind
select * from people p left join customfields on p.customfield = c.fieldID where c.fieldID=4 and p.customvalue="blind"
This finds
pat,4,blind
lisa,4,blind
how do I get the more complete list
Open in new window