Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

search an sql database

Posted on 2012-03-19
3
Medium Priority
?
247 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 1000 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

782 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