Solved

search an sql database

Posted on 2012-03-19
3
240 Views
Last Modified: 2012-03-19
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
0
Comment
Question by:joomla
3 Comments
 
LVL 24

Accepted Solution

by:
johanntagle earned 250 total points
ID: 37736639
Try:

select pp.* from people join people p on pp.username=p.username left join customfields on p.customfield = c.fieldID where c.fieldID=4 and p.customvalue="blind"
0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37736660
select * from people a inner join customfields b on a.customfield=b.fieldid where b.fieldid=4 and p.customvalue='blind'

Open in new window

0
 

Author Closing Comment

by:joomla
ID: 37736699
thank you
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question