View Full Version : Unsortable Query


tr10101
06-30-2008, 01:59 PM
I recently created a query to display the first record out of a one to many relationship rather than showing all instances, ie

Hearing 1; Asset 1; Hearing 1 Details
Hearing 2; Asset 3; Hearing 2 Details

Rather than:

Hearing 1; Asset 1; Hearing 1 Details
Hearing 1; Asset 2; Hearing 1 Details
Hearing 2; Asset 3; Hearing 2 Details
Hearing 2; Asset 4; Hearing 2 Details
Hearing 2; Asset 5; Hearing 2 Details

This was accomplished through a combination of using first and group by. I realize that the recordset won't be updateable because of the group by, yet now I recieve an error message everytime I try to sort by any field saying there's an unknown error.

My query's sql:
SELECT Hearings.[Multi Folio], Hearings.[Hearing ID], Hearings.Petition, First(Clients.ID) AS ID_Clients, First(Assets.ID) AS ID_Assets, First(Assets.Folio) AS Expr1, AssetGroups1.[Asset Group] AS [Asset Group], Hearings.[Hearing Date], First(Assets.Client) AS Client, Hearings.[Evidence Due], First(Assets.Address) AS Address, First([Tax Millage Rates].[Millage Code]) AS [Millage Code], First([Tax Millage Rates].Municipality) AS Municipality, First(Assets.[PA Web Link]) AS [PA Web Link], First(Assets.Attachments) AS FirstOfAttachments, First(Clients.Company) AS Company, First(Assets.County) AS County, First(Assets.[Property Type]) AS [Property Type], Hearings.Multi, Hearings.[Prepared by N], Hearings.Withdrew, Hearings.[N/C], Hearings.[Hearing Agent N], Hearings.[No Cut], First(Assets.[2007 Value]) AS [2007 Value], Hearings.Comments, Hearings.Legal, Hearings.[Legal Hearing Type], Hearings.[Reduced Amount], First(Assets.[Historic Property]) AS [Historic Property], First(Assets.[Historic Prop Web Link]) AS [Historic Prop Web Link], First(Assets.[Homestead Status]) AS [Homestead Status], Hearings.[Evidence Sent]
FROM Clients RIGHT JOIN ([Tax Millage Rates] RIGHT JOIN (AssetGroups1 RIGHT JOIN (Hearings INNER JOIN Assets ON Hearings.[Hearing ID]=Assets.[Hearings ID]) ON AssetGroups1.ID=Assets.[AG ID]) ON [Tax Millage Rates].ID=Assets.[Millage ID]) ON Clients.ID=Assets.Client
GROUP BY Hearings.[Multi Folio], Hearings.[Hearing ID], Hearings.Petition, AssetGroups1.[Asset Group], Hearings.[Hearing Date], Hearings.[Evidence Due], Hearings.Multi, Hearings.[Prepared by N], Hearings.Withdrew, Hearings.[N/C], Hearings.[Hearing Agent N], Hearings.[No Cut], Hearings.Comments, Hearings.Legal, Hearings.[Legal Hearing Type], Hearings.[Reduced Amount], Hearings.[Evidence Sent];

I know its alot of code to look at but does anyone have any general idea why a query like this won't sort?