|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
SQL Query question
SQL Query Question
Given the following data: table1 ---------- |stuName | stuFavoriteFruit | I need to construct a query to answer two questions, while not knowing the data in the tables. 1. Who likes all the fruits? 2. List all the people that like fruits that Aaron likes. For 1. I think I have to SELECT DISTINCT the stuFavoriteFruit field, but I'm not sure how I can get a count back on that and compare it to the student names to findout who likes all teh fruits. Any help would be much appreciated! |
|
#2
|
||||
|
||||
|
Quote:
How do you know how many fruits there are? Quote:
How do you know if Aaron is even in the database, if you can't see the data??? Without sample data, no one is going to be able to help you. |
|
#3
|
||||
|
||||
|
Here's a shot
Get all fruits Code:
SELECT DISTINCT stuFavoriteFruit FROM TableName Get names of everyone who selected all the fruits Code:
SELECT DISTINCT stuName FROM TableName WHERE stuFavoriteFruit IN ( SELECT DISTINCT stuFavoriteFruit FROM TableName ) Get all fruits Aaron likes Code:
SELECT DISTINCT stuFavoriteFruit FROM TableName WHERE stuName = 'Aaron' Get others who like the same fruits Aaron likes Code:
SELECT DISTINCT stuName FROM TableName WHERE stuFavoriteFruit IN ( SELECT DISTINCT stuFavoriteFruit FROM TableName WHERE stuName = 'Aaron' ) |
|
#4
|
|||
|
|||
|
Memnoch, Thanks for the help!
Q1 I don't think is working correctly. Q2 looks good, but not sure if it is what is needed I willwork with both of them and post any questions. Thanks again! Attached is the data I'm working with. |
|
#5
|
|||
|
|||
|
Yea query 2 needs to be people that like all 3 fruits that Aaron likes, so Denny and Gina.
|
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > SQL Query question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|