Sql Query Problem with Sql Server

  • From: "Ricks Place" <OFBGMail@xxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Thu, 12 Jun 2008 07:36:31 -0400

Hi Guys: I have a Sql Server table with about 40 columns.
I want to select the rows, all columns, where 1 of the columns comprise a 
distinct constraint.
I  Created strSelect: 
Select Distinct PortfolioName From UserPortfolios  
Where UserId = 'Richard';
It only returns the field specified but a GridView bind expects an entire 
table, about 40 fields so fails.
So I think I need to select the distinct field, PortfolioName,  then select the 
entire row for each distinct PortfolioName in the first select.
A subquery, according to what I'm reading only  returns one column.  Do I need 
to use a join or  would it be called something else?
For Example:
I was thinking of:
Select Distinct PortfolioName, PortfolioPrimaryKey From UserPortfolios
Select * from UserPortfolios where PortfolioPrimaryKey = the selected key in 
the above statement
How would you handle something like this? Am I on the right track ro could you 
suggest something I can use or research more?
Rick Farmington Mich. USA

Other related posts: