Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Question about a query result

Author  Topic 

spider3
Starting Member

11 Posts

Posted - 2007-06-26 : 07:37:09
Hi Everyone, I've created a small exmaple database. The tables are:

TABLE Cocktails
CocktailID (int, PK)
CocktailName (varchar)
CocktailDescription (varchar)

TABLE Ingredients
IngredientID (int, PK)
IngredientName (varchar)

TABLE CocktailIngredients
CocktailID (int, PK)
IngredientID (int, PK)
QuantityNeeded

In this way, i can perform a query like:

SELECT
Cocktails.CocktailName, CocktailIngredients.CocktailIngredientQuantity, Ingredients.IngredientName, Cocktails.CocktailDescription
FROM CocktailIngredients INNER JOIN Cocktails ON CocktailIngredients.CocktailID = Cocktails.CocktailID INNER JOIN Ingredients ON CocktailIngredients.IngredientID = Ingredients.IngredientID

As result, I obtain the data I needed, like:

MyCocktail1 2dl Rum DescrptionOfMyCocktail
MyCocktail1 1dl Gin DescrptionOfMyCocktail
MyCocktail1 2st Lemons DescrptionOfMyCocktail
MyCocktail2 1dl Rum DescrptionOfMyCocktail
...

The name "MyCocktail1" and "DescrptionOfMyCocktail" is repeated every row, and I've been asked to find a way to avoid getting back a table with information I need only one time.

Is there something wrong in the structure of my tables? Or there is a way to perform the query in a different way and have empty fields after the first description? (of course it will be written again if cocktail name changes)

thank you a lot!


blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2007-06-26 : 09:50:14
Your query is fine and works exactly the way it should. Each row is atomic, and SQL Server is not going to return partial data for a record.
The job of hiding repeated values is a task for your presentation/reporting application (Crystal reports, MS Access, SQL Server Reporting Services, ASP, whatever...).

e4 d5 xd5 Nf6
Go to Top of Page

spider3
Starting Member

11 Posts

Posted - 2007-06-26 : 10:19:17
Exacly as I thought ^^ thanks a lot for your confirmation!
Go to Top of Page
   

- Advertisement -