rskyles — 2010-02-23T12:00:25-05:00 — #1
Is there a way to display a COUNT of these Inner Joined records? Right now, my .NET Datalist is listing all of the records for this team; however, I just want it to count the number of records and then let me display the most recent TIME (my field is "fldDate") for the most recent CP reached.
"SELECT * FROM (tblEvents INNER JOIN (tblCategory INNER JOIN " & _
"tblRegistrationBasic ON [tblCategory].[CategoryID]=[tblRegistrationBasic].[CategoryID]) ON " & _
"[tblEvents].[EID]=[tblRegistrationBasic].[EventID]) INNER JOIN tblCPReached ON " & _
"[tblRegistrationBasic].[RID]=[tblCPReached].[Team] " & _
"WHERE tblEvents.EID=" & _
Request.QueryString("id") & " ORDER BY Chek DESC", objConn)
dan_grossman — 2010-02-23T12:12:58-05:00 — #2
SELECT COUNT(*), MAX(fldDate)
rskyles — 2010-02-23T12:57:53-05:00 — #3
I'm not a programmer (just reading books), so where in my existing code would I add that information?
Sorry to ask a stupid question, but thank you
dan_grossman — 2010-02-23T13:01:50-05:00 — #4
Instead of SELECT *, which asks for all the columns of the tables.
r937 — 2010-02-23T13:48:45-05:00 — #5
and don't forget to remove the ORDER BY clause
rskyles — 2010-02-23T14:55:05-05:00 — #6
Now I get the error:
DataBinding: 'System.Data.Common.DataRecordInternal' does not contain a property with the name 'RID'
"RID" is the first column in my "tblRegistrationBasic" table.
Not sure why it's not finding that column :/
dan_grossman — 2010-02-23T14:58:36-05:00 — #7
You're no longer selecting that column -- you said you only want to get the count and the maximum date. That's what the query will give you. You can't bind it to some interface designed to show something else.
rskyles — 2010-02-23T15:07:54-05:00 — #8
Oh, so I can't display items from the INNER Joined tables, while counting the number of records for each similar item and then order by the number collected?
Team Name CPs Collected
Joe Blow 4
r937 — 2010-02-23T15:11:30-05:00 — #9
actually, you can, but they all have to be within an aggregate function
if you want counts per team (as your last example suggested), you also need a GROUP BY clause
SELECT tblCPReached.Team AS 'Team Name'
, COUNT(*) AS 'CPs Collected'
ON tblRegistrationBasic.EventID = tblEvents.EID
ON tblCategory.CategoryID = tblRegistrationBasic.CategoryID
ON tblCPReached.Team = tblRegistrationBasic.RID
WHERE tblEvents.EID = Request.QueryString("id")
BY COUNT(*) DESC
rskyles — 2010-02-23T15:47:03-05:00 — #10
Same error. Thanks for trying, though, guys.
dan_grossman — 2010-02-23T16:17:04-05:00 — #11
The error doesn't mean the query's wrong. I don't think you want to bind this to something designed to show individual objects based on a single table.
rskyles — 2010-02-23T16:26:35-05:00 — #12
I just created a manual leaderboard. I'm going to edit the time and last CP for each team and have it sort that way. My race is this weekend. I'll try to build one that automatically does it later. Here is a sample of what I'm doing