Re: Sql Query Problem with Sql Server

  • From: "black ares" <matematicianu2003@xxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Thu, 12 Jun 2008 21:49:12 +0300

hmm
by definition a portfolioprimary key is distinct
so if you make distinct after primary key
you get all the records. On the other hand
you have let say 3 records two of them having same portfolioname
when you mean you want rows, all columns, for which 1 column satisfy a distinct 
constraint.
Regarding the above case where you have 3 records two of them let say 1 and 3 
having same portfolioname
which one do you want to optain?
Clear what you want to obtain and see if the design of the table is the best 
one to answer to your question.


  ----- Original Message ----- 
  From: Rodney Haynie 
  To: programmingblind@xxxxxxxxxxxxx 
  Sent: Thursday, June 12, 2008 5:16 PM
  Subject: RE: Sql Query Problem with Sql Server


  Is it possible for a user to have the same PortfolioName more than once?  If 
not, then there is no reason for a distinct, and the following will work for 
you.

   

  Select * From UserPortfolios  
  Where UserId = 'Richard';



   

  HTH.

  -Rodney

   

   

  From: programmingblind-bounce@xxxxxxxxxxxxx 
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Ricks Place
  Sent: Thursday, June 12, 2008 7:37 AM
  To: programmingblind@xxxxxxxxxxxxx
  Subject: Sql Query Problem with Sql Server

   

  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: