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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Using DISTINCT but getting wrong results

Author  Topic 

mtaplits
Starting Member

6 Posts

Posted - 2004-01-04 : 11:44:48
Hi,

I'm trying to do a query, joining two tables and displaying the distinct results.

My query:
<cfquery name="resultsName" datasource="formal">
SELECT DISTINCT ri.restaurantID, ri.restaurantName, rc.cuisine, c.cuisineName
FROM restaurantInfo ri, restaurantCuisine rc, cuisine c
WHERE ri.restaurantID= rc.restaurant
<cfif NOT #selectCuisine# IS 1000>AND rc.cuisine=
#selectCuisine#</cfif>
AND rc.cuisine= c.cuisineID
</cfquery>

You see, I want to view the distinct results based on ri.restaurantID and not all of the items in my select statement. Is this possible?

Thanks.

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2004-01-04 : 19:48:58
I don't understand what you're looking for. Are you saying that you only want one row for each restaurant and that it can display any one rc.cuisine and any one c.cuisineName? Or are you looking for a particular cuisine that should be displayed? I don't think DISTINCT is really the statement you are looking for. Just taking a guess that what you're going to end up with will be a GROUP BY with a MIN() statement, but that's really just a WAG.

Perhaps if you could provide some sample data (preferably in the form of CREATE TABLE and INSERT statements) with sample results that you'd like to see, we could help you form your query better.

--------------------------------------------------------------
Find more words of wisdom at [url]http://weblogs.sqlteam.com/markc[/url]
Go to Top of Page

mtaplits
Starting Member

6 Posts

Posted - 2004-01-07 : 02:07:15
Thank you for your assistance but I was finally able to figure it out.

Go to Top of Page

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2004-01-07 : 13:47:39
Hey, that's great! Why don't you post your solution here so that when others come searching for answers they'll have yours to read, too?

--------------------------------------------------------------
Find more words of wisdom at [url]http://weblogs.sqlteam.com/markc[/url]
Go to Top of Page
   

- Advertisement -