Thursday, March 22, 2012

Distinct in Select Statement

Hey there, is there a way I can use command such as distinct in a select statement to do the following. Lets say I want to do a search of products based off their location and I want to list the companies that will have products in that area. I only want to list the company once, but if I'm searching by products in the area I might come up with 15 results for that company. I have not written the code yet for this, I'm just planning ahead.

I'm programming using VB so I guess I would do something like this.

State = Trim(Request.QueryString("State"))

SelectStatement = "Select * From Products Where State='" & _
State & "'"

This would of course give me hypothetically speaking a list as long as the amount of products in one given area. Is there a way to cut this down and only list the company once? Any help would be greatly appreciated. Thanks in advance.SELECT DISTINCT(CompanyName)
FROM Company
WHERE Product.State = stateVariable
AND Product.CompanyID = Company.CompanyID|||thanks, I'll give that a shot.

No comments:

Post a Comment