I have a query in which I want to filter and merge data together. As is the SQL for the query looks as such:
SELECT UCase$(DLookUp("Abbreviation", "tblRankStructure", "tblRankStructure!ID = " & [tblRoster].[Rank])) AS Rank
,UCase$([tblRoster].[LastName] & ", " & [tblRoster].[FirstName] & " " & IIf(IsNull([tblRoster].[MiddleName]), "", Left$([tblRoster].[MiddleName], 1))) AS [Full Name]
,tblRoster.EDIPI
,tblBasicIndividualRecords.PriMilOccSpec AS MOS
,tblBasicIndividualRecords.Gender
,tblBasicIndividualRecords.BloodType
,tblUnitInformationCodes.PltCode
,IIf(IsNull([tblBasicIndividualRecords] ! [MealCardNumber]), "COMRATS", [tblBasicIndividualRecords] ! [MealCardNumber]) AS [Meal Card]
,tblBasicIndividualRecords.SecurityClearance AS Clearance
,tblBasicWeaponRecords.WeaponType
,tblBasicWeaponRecords.WeaponSerial
,tblBasicWeaponRecords.OpticSerial
FROM (
(
(
tblRankStructure INNER JOIN tblRoster ON tblRankStructure.ID = tblRoster.Rank
) INNER JOIN tblBasicIndividualRecords ON tblRoster.EDIPI = tblBasicIndividualRecords.EDIPI
) LEFT JOIN tblBasicWeaponRecords ON tblRoster.EDIPI = tblBasicWeaponRecords.EDIPI
)
INNER JOIN tblUnitInformationCodes ON tblRoster.EDIPI = tblUnitInformationCodes.EDIPI;
With the query as such it will return as rows for the same person if they have multiple weapons. How can I merge to return same data but only one row from the query and still display all required data?
What I would like is to have the row with the M9A1 serial under the pistol serial column and only have one row for SSgt Pilewski
This sample is created by added another field to the tblBasicWeaponRecords for the PistolSerial. I do not want this field there and would like to make my query work with out having this field in the tblBasicWeaponRecords.
All data is pulled from the following tables:
tblRoster
+-------+------------------+----------+-----------+------------+
| EDIPI | Rank | LastName | FirstName | MiddleName |
+-------+------------------+----------+-----------+------------+
| | First Lieutenant | Mozzetta | Jennifer | L |
| | Staff Sergeant | Pilewski | Troy | Andrew |
| | Sergeant | Irizarry | Jonathon | |
+-------+------------------+----------+-----------+------------+
tblBasicIndividualRecords
+----+-------+-------------+------------+-------------------------------+--------------------+---------------+---------------+--------+------------+--------+---------+--------+-----------+-------------------+----------------+-----------------+
| ID | EDIPI | DateOfBirth | DateOfRank | ArmedForcesActiveDutyBaseDate | EndOfActiveService | PriMilOccSpec | AddMilOccSpec | Billet | Deployable | OnHand | Remarks | Gender | BloodType | SecurityClearance | MealCardNumber | MartialArtsBelt |
+----+-------+-------------+------------+-------------------------------+--------------------+---------------+---------------+--------+------------+--------+---------+--------+-----------+-------------------+----------------+-----------------+
| 1 | | | | | 12-Aug-2015 | 0602 | | | TRUE | TRUE | | | | | | |
| 2 | | | | | 23-Aug-2014 | 0659 | | | TRUE | TRUE | | | | | | |
| 3 | | | | | 30-Aug-2013 | 0651 | | | TRUE | TRUE | | | | | | |
+----+-------+-------------+------------+-------------------------------+--------------------+---------------+---------------+--------+------------+--------+---------+--------+-----------+-------------------+----------------+-----------------+
tblBasicWeaponRecords
+----+-------+------------+--------------+-------------+
| ID | EDIPI | WeaponType | WeaponSerial | OpticSerial |
+----+-------+------------+--------------+-------------+
| 1 | | M4 | W151644 | 224604 |
| 3 | | M4 | W142663 | 228541 |
| 4 | | M16A4 | 164522845 | 225487 |
| 6 | | M9A1 | 1476541 | |
+----+-------+------------+--------------+-------------+
tblUnitInformationCodes
+----+-------+---------+
| ID | EDIPI | PltCode |
+----+-------+---------+
| 1 | | CYB |
| 2 | | CYB |
| 3 | | CYB |
+----+-------+---------+