ADO.NET :: How To Select Distinct With Count
		
			Nov 3, 2010
				This is something I can easily do in SQL, but I'm pretty new to LINQ and haven't been able to find an answer online.
I need a LINQ query that returns two values; the first a distinct value and the second the count of the first value. This is filtered by a parameter. Here is my table:
[code]....
	
	View 2 Replies
  
    
		
Similar Messages:
	
    	
    	
        Apr 20, 2010
        I would like to select a distinct query based on three fields and display the rest of the fields.  For example,
I have firstname, lastname, address, city, state and zip, but  I only want to use the  distinct on these fields first and last name.  However when i use the distinct function I get a distinct on all the selected rows.  I just want to distinct firstname and lastname and display the other fields.  for example,
Mary Smith    New York
Mary Smithy  New York
Mary Smith    Maine
I would like the result to be:
Mary Smith    New York
Mary Smithy  New York
I don't care about Mary Smith Maine, because i am only using the distinct for "Mary Smith" firstname and last name and showing the city. 
	View 15 Replies
   
  
    
	
    	
    	
        Jan 6, 2010
        I have an object, that has many properties but the only two to worry about are:
myobject.ID which is an int
myobject.Names which is a HashSet
Then I have a List of those objects that looks something similar to this:
List<myobject>
I use Linq to get a some of the data into a repeater, but I'm not sure how to get the list of Names and how often they show up.
Want to use Linq to avoid having to loop through the data.
As my tags should show, this is an ASP.NET solution using C#.
Some clarification:
Lets say I have just three items in my list:
Item 1 has John, Fred, Jack in its names.
Item 2 has John, Fred, Joe in its names.
Item 3 has John in its names.
I am trying to return the following:
John - 3
Fred - 2
Jack - 1
Joe - 1
Also, as a note I am familiar with having to write my own comparer for my object, I'm just missing the 'how to' for the overall solution in my thoughts.
	View 2 Replies
   
  
    
	
    	
    	
        Feb 26, 2011
        how to write a select distinct column1 from another select ?
i mean SELECT distinct column1 from (SELECT column1,column2,column3 where column1 =1)
	View 1 Replies
   
  
    
	
    	
    	
        Feb 9, 2011
        Having some troubles selecting distinct rows.
[Code]....
This is not giving me the wanted results.
Two models:
[code]....
Each ContentVersion is linked to Content through the ContentID.
I want to select all "Content" where UserID = X, then for each selected "Content" I want the latest "ContentVersion".
The return type should be of type <IQueryable>ContentVersion.
	View 21 Replies
   
  
    
	
    	
    	
        Nov 24, 2010
        1.Category:
CatID(Pkey),
CatName,
ParentCatId(Fkey)=> CatID is used as a ParentCatId
2.Comp_Cat:
CCID(Pkey),
CatID,(fkey),
CompID
In my stored Procedure I am passing PageNo,CompID.. My requirement is that One parent CatName is displayed Per page but only one time.  
	View 4 Replies
   
  
    
	
    	
    	
        Mar 21, 2011
        how can i use Distinct in my sql statement like that 
SELECT
Distinct * from my_table ?? ? ? ?? ? ? ?
	View 2 Replies
   
  
    
	
    	
    	
        Nov 16, 2010
        I have an already created DataTable object which i am using for my girdview (asp.net) i also need to bind a column of that object to a DropDownList. The datatable has the correct details in the column but the column contains more that 1 of the same name in the column - hence I would love to just do some kind of SELECT DISTINCT on the datatable and copy it to a new datatable for use with binding the dropdown. 
This would allow me to save resources by making another trip to the database.
Here is an example, the current datatable has a column called items and in this column has the following entries
1
1
1
1
5
5
6
And of course i need only unique items for binding to my dropdown, hence i need the following data
1
5
6
Of course i don't want to change the original datatable object but rather make a copy of it will the new details.
	View 2 Replies
   
  
    
	
    	
    	
        Dec 29, 2010
        How can i select all columns of table but to distinct by one column? i am tryin to figure it out without success, i know how to make distinct (select distinct column from table, but i need all the values from the table and to distinct by Delcompany.
my line is:
[Code]....
	View 13 Replies
   
  
    
	
    	
    	
        May 2, 2010
        I'm using asp.net login on a SQL Database.
I have 12 users in my User tabel - one of the user I don't want to have in my select (the user is an admin).
I tried this:
[Code]....
I also tried:
WHERE     (dbo.aspnet_Roles.RoleName <> 'Administrators')
Both time it took the user into the table....
If I instead try this
WHERE     (dbo.aspnet_Roles.RoleName = 'Administrators')
I get only one row (as expected).
What is wrong with the above sql statement - why can't I get 11 users and not them all (12 users)?
	View 3 Replies
   
  
    
	
    	
    	
        Jun 3, 2010
        <
asp:LinqDataSource
ID="LinqDataSourceSM"
runat="server"
ContextTypeName="SalesIntranetSolution.DataClasses.salesIntranetDataClassesDataContext"
OrderBy="reportTo"
Select="new (reportTo)"
TableName="cubeSalesRepRollups">
</asp:LinqDataSource>
Does somebody know how I can modify this LinqDataSource to select distinct records only?
	View 1 Replies
   
  
    
	
    	
    	
        Jan 2, 2010
        there are multiple rows with same SubContact_No and with same value of some columns. for a single column I am firing query like
Select distinct (Financial_Status) from mtblSub_Contract where SubContract_No=@SubContract_No";
it's working fine.... (it's ok with a Single column)
But Now  I need  multiple columns value so how to query for this.
Select distinct (Financial_Status, colums2, column3) from mtblSub_Contract where SubContract_No=@SubContract_No"; is not working
So how to do that.
	View 5 Replies
   
  
    
	
    	
    	
        Sep 30, 2010
        I have the following table structure:
[code]....
The following query returns the default recordset:
[code]....
	View 4 Replies
   
  
    
	
    	
    	
        Feb 4, 2011
        I have a page where I'm displaying all the different brand that I company stocks
For each distinct brand I need to display a count of the number of items with that particular brand
e.g.
brand name
number of products with that brand
brand name 2
number of products with that brand
brand name 3
number of products with that brand
	View 2 Replies
   
  
    
	
    	
    	
        Mar 17, 2010
        I have a SQL select statement with inner joins to get a total number of records for the statement. I have tried using count with group by's but it just counts one for each record instead of giving me the total number of records for the query. Here is the query:
[Code]....
	View 3 Replies
   
  
    
	
    	
    	
        Mar 14, 2010
        I am trying to count records belonging to a certain person in three different tables in a single select statement. The database looks like this:
Player
 -PlayerId
 -Name
Game
 -GameId
 -TournamentId
 ...
Goal
 -GameId (FK->Game.GameId)
 -PlayerId (FK->Player.PlayerId)
 -Assist (FK->Player.PlayerId)
Card
 -CardId
 -GameId (FK->Game.GameId)
 -PlayerId(FK->Player.PlayerId)
I want to select the number of goals, assist and cards a player has in a specific tournament. I tried with this query but then the goal and card column shows the sum of the number of rows matching the playerid in the Goal table and the Card table...For example if there is two matching rows in the goal table and three matching rows in the card table, I get 5 in both these columns in the resultset.
[Code]....
	View 3 Replies
   
  
    
	
    	
    	
        Feb 14, 2011
        the select statement for my gridview contains a sub select statement..that should allow users to see how many queries are associated with a particular record..how can I get the queries column to display in my grid. As it is a count and  not directly bound to any field
SELECT 
WardID, 
ScriptID, 
DateAdded,
(SELECT COUNT(scriptID) FROM query WHERE scriptID = main.scriptID) AS queries.......
	View 2 Replies
   
  
    
	
    	
    	
        Feb 9, 2011
        I have many record in my sql table and i want to fetch last row of  table.I have used max function but it is very slow
i m using this query-
select  pm_name  from datos where  date_time = (select Max(date_time) from datos) but it takes more time i want to use select count(date_time) from datos this query provide me row number then how can fetch row of this number.
	View 11 Replies
   
  
    
	
    	
    	
        Mar 22, 2010
        Anyone know how to write a select statement to where it returns results that have a specific character count?  I want to return all results that have 5 characters. 
	View 1 Replies
   
  
    
	
    	
    	
        Feb 4, 2011
        I have one table(tableName is getDetails and having three column ID, Name, City)
	View 6 Replies
   
  
    
	
    	
    	
        Jun 4, 2010
        In the GridView_RowUpdated event the e.OldValues.count <> e.NewValues.Count. 1 out of 5 columns has been converted to a template field. 
	View 9 Replies
   
  
    
	
    	
    	
        Dec 17, 2010
        When a user submits the query to SQL when clicking a button I need to get a count of the number of rows that are returned.  Which event does the gridview.count code need to be place in? 
Right now I have it in the btn_click event, but in order to get it to count the rows you have to hit the button twice since the query is not returned yet.  Here is my code.
[Code]....
	View 1 Replies
   
  
    
	
    	
    	
        Oct 5, 2012
        I HAVE A GRID VIEW IN asp.net + VB Code. There is a drop down list and the selected data is displayed in web page. I placed a label in web page and code behind i used following code.
Protected Sub GridView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.DataBound
        Label1.Text = GridView1.Rows.Count.ToString()
        Dim ONYO As Integer = 0
        Dim DONE As Integer = 0
        For i As Integer = 0 To GridView1.Rows.Count - 1
            If GridView1.Rows(i).Cells(0).Text = "ON YO" Then
[Code] .....
	View 1 Replies
   
  
    
	
    	
    	
        Sep 18, 2010
        I have a problem with SELECT COUNT query in ASP.net. I want to create CMS with articles which have categories (which have the option to be deleted). The problem is that I want to get the number of articles within the specified category so if there aren't any articles with the specified category I can proceed with the category deletion.I have the following code:
[Code]....
After I click the button "ObriĊĦi" (Delete) I receive the following error: "Must declare the scalar variable "@KategorijaID"." I understand that the problem is with parameter, but I don't know how to correct it to use it for both the "command" and "brisanje" SQLCommands.
	View 9 Replies
   
  
    
	
    	
    	
        Oct 13, 2010
        I have tableone:
rowid    pid       gid     dis
1         1222     aa      dd
2         1222     bb      cc
3         1222     cc      dd
4         1331     vv      cc
5         1331     cc      zz
6         1414     zz     cc
5         1414     xx     zz 
I need get distinct pid with rowid together. select * distince pid from tableone However, I get  error: select rowid, distinct pid from tableone? Is any way to work out this one?
	View 4 Replies