homepage Welcome to WebmasterWorld Guest from 107.21.156.140
register, login, search, subscribe, help, library, PubCon, announcements, recent posts, open posts,
Subscribe and Support WebmasterWorld
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library : Charter : Moderators: physics & whoisgregg

Databases Forum

    
Multiple Value SQL Issue
wfernley




msg:4505757
 4:44 am on Oct 9, 2012 (gmt 0)

Hey everyone, I'm having an issue with a SQL command. I have multiple "apples" and need to find apples that match a specific criteria.

Here is the database structure:

apple_id type_id type_value
1 Color Red
1 Size Small
2 Color Green
2 Size Small
3 Color Red
3 Size Small
4 Color Yellow
4 Size Big

I'm trying to find an apple that is Red & Small.

This is a basic example of what I am looking to do. The actual database has several types and values. What is the SQL command I would use?

Thanks in advance for your help!

 

mark_roach




msg:4506860
 10:14 am on Oct 11, 2012 (gmt 0)

You need to join the table with itself. Try something like this (untested):

select a.apple_id from table a, table b where a.apple_id=b.apple_id and a.type_id='Color' and a.type_value='Red' and b.type_id='Size' and b.type_value='Small'

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
WebmasterWorld ® and PubCon ® are a Registered Trademarks of Pubcon Inc.
© Pubcon Inc. 1996-2012 all rights reserved