Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Complex SQL query

Status
Not open for further replies.

ResolutionsNET

IS-IT--Management
Jul 31, 2000
70
GB
Hi,

I've got a problem, I need a SQL query that I can't get my head around can anybody help??

I have 5 tables
Recipes - id, name
FoodType - id, name
MealType - id, name
RecipeFoodRelation - recipe id and foodtype id
RecipeMealRelation - recipe id and Mealtype id

I want to be able to list the Recipe ids, its name and it's food type for a particlue meal type.

I've tried various methods but I keep getting some duplicate records.

The nearest I've got is something like this

select a.RecipeID, c.Name, b.FoodTypeID
from RecipeMealRelation a, FoodRecipeRelation b, Recipe c
where a.MealTypeID=1 and a.RecipeID=b.RecipeID and a.RecipeID=c.id

umm help
 
If the only problem is eliminating duplicates, use the DISTINCT keyword: SELECT DISTINCT col1, col2, etc.....
 
Hi Winter.... can you provide us sample data and how you want your query result to look like?
Andel
andelbarroga@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top