Solved

search an sql database

Posted on 2012-03-19
3
239 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

Suggested Solutions

Title # Comments Views Activity
mysql Encryption with PHP 8 95
Selecting specific rows 3 50
sql select time convert to  time to   a   b mysql 4 40
MySql hide the stored procedures 2 38
Creating and Managing Databases with phpMyAdmin in cPanel.
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

919 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now