I tabellen kan man oprette flere jobs under samme bruger. Og jeg vil gerne lave en komplet liste der lister alle, men den skal "skjule" dubletter og kun vise den nyeste (ud fra DatoB) for hver EmpId.
Min select ser sådan ud: SELECT [tblEmploy].[EmpId] AS tblEmploy_EmpId, [tblEmploy].[Init], [tblJobs].[JobId] AS tblJobs_JobId, [tblJobs].[Title], [tblTraining].[TrainingId], [tblTraining].[EmpId] AS tblTraining_EmpId, [tblTraining].[JobId] AS tblTraining_JobId, [tblTraining].[DateB], [tblTraining].[DateE], [tblTraining].[Approval], [tblTraining].[TrainedBy] FROM tblJobs INNER JOIN (tblEmploy INNER JOIN tblTraining ON [tblEmploy].[EmpId]
The two lines you are indicating have the same datoB!
Are you saying that you only want to see the one with the highest TrainingId?
If so, then do this Make a query where you Groupp on EmpId and DateB and choose Max for Training Id. Don't select any other fields.
Now save the query.
Now make another query where you select all of the fields from the query you just made. Add the table to the query again and make a join on TrainingId between the first query and the table. Now select the remaining fields from the table.
Mugs gav mig dette: SELECT TOP 1 tblTraining.EmpId, tblTraining.JobId, tblTraining.DateB FROM tblTraining ORDER BY tblTraining.DateB DESC;
Og det virker i min form. Men jeg skal bruge data fra 2 andre tabeller som tblTraining har relation til, og jeg ved ikke hvordan jeg kobler det på ovenstående.
Det vil sige at jeg skal have denne her funktion: SELECT TOP 1 tblTraining.EmpId, tblTraining.JobId, tblTraining.DateB FROM tblTraining ORDER BY tblTraining.DateB DESC;
sat ind i denne her: SELECT [tblEmploy].[EmpId] AS tblEmploy_EmpId, [tblEmploy].[Init], [tblJobs].[JobId] AS tblJobs_JobId, [tblJobs].[Title], [tblTraining].[TrainingId], [tblTraining].[EmpId] AS tblTraining_EmpId, [tblTraining].[JobId] AS tblTraining_JobId, [tblTraining].[DateB], [tblTraining].[DateE], [tblTraining].[Approval], [tblTraining].[TrainedBy] FROM tblJobs INNER JOIN (tblEmploy INNER JOIN tblTraining ON [tblEmploy].[EmpId]
Mugs, din løsning var rigtig til det oprindelige spm. Smid svar. :)
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.