I have a One-to-Many relationship in my database between the [Customer] and [Car] tables where one customer may have zero or more cars.
My project requires me to output a listing of all customers with a single column showing the vehicle registration(s), [VehicleReg], from the cars. Where a customer has multiple cars all their the vehicle registrations must be shown separated by commas. Where a customer has no cars the column should be blank.
This is the basis of the query but I can't work out how to return the registration numbers.
SELECT [Customer].[FirstName], [CustomerLastName], COMMA SEPARATED VEHICLE REGS FROM [Customer] LEFT JOIN [Car] ON [Customer].[CustomerId] = [Car].[fkCustomerId]
The output I am looking for would be like this
FirstName | LastName | VehicleRegistrations
-------------------------------------------------
John | Smith | MY51 4RT
Joe | Mason | MU08 5TH
Connor | Norman |
Graham | Naughton | HT09 6TY, HT11 8UQ
Lilly | Adams | JK55 8HY
I am using a MS Access 1997 database, C# and .NET 4.0.
Performance isn't an major issue at this stage.
The only working solution I have so far is to save the vehicle registrations into a column in the [Customer] table. While this will work it will involve manually keeping the new column in sync with any changes made to the vehicle registrations in the [Car] table, something that isn't too difficult but may be a dangerous approach once I pass the project on to other to maintain.
Many Thanks