I have a form where I am trying to display a summary of records in a ListView.
The SQL is:
SELECT MatchClassID, MatchClassName, Count(tblMatchID) FROM (SELECT tblMatch.ID As tblMatchID, tblSeries.MatchClassID As MatchClassID, tblMatchClass.ClassName As MatchClassName FROM (tblMatch LEFT JOIN tblSeries ON tblMatch.SeriesID = tblSeries.ID) LEFT JOIN tblMatchClass ON tblSeries.MatchClassID = tblMatchClass.ID WHERE (tblMatch.Complete = True) ORDER BY tblMatch.ID ) GROUP BY MatchClassID, MatchClassName
The code to get the data is a follows:
Dim objCommand As OleDb.OleDbCommand
If ConnectToDatabase() = True Then
objCommand = New OleDb.OleDbCommand(strQuery, conDb)
oDR = objCommand.ExecuteReader
Return True
Else
Return False
End If
Where strQuery contains the SQL statement above.
This should return 3 rows and 3 columns however it is returning over 3000 rows. What it is doing is returning the results of the sub-query ie before the aggregation. If I just take the SQL and run it against the database directly I get the correct results so I know the SQL is right. What I cannot understand is why different results are being loaded into the Reader. I have used far more complex aggregate queries with Readers and not had this problem.
Can anyone help?
Thanks.