SELECT 
    `t7`.`TestId`,
    `t7`.`ExaminerFlagId`,
    `t7`.`Id`,
    `t7`.`ExaminerId`,
    `t7`.`Code`,
    `t7`.`FlagTypeId`,
    `t7`.`SKUTypeId`,
    `t7`.`IsBlocking`,
    `t7`.`IsDeleted`,
    `t7`.`IsErrorCode`,
    `t7`.`IsSKURelated`,
    `t7`.`Label`,
    `s`.`Id`,
    `t`.`Id`,
    `t0`.`Id`,
    `t1`.`Id`,
    `p0`.`Id`,
    `p1`.`AssemblyId`,
    `p2`.`Id`,
    `p3`.`Id`,
    `g`.`Id`,
    `d`.`Id`,
    `p4`.`Id`,
    `t2`.`Id`,
    `t3`.`Id`,
    `t3`.`Id0`,
    `t3`.`ExamSettingVersionId0`,
    `t3`.`ExamSettingVersionId1`,
    `t3`.`ExamSettingVersionId2`,
    `t3`.`Id1`,
    `t3`.`Id2`,
    `t3`.`Id3`,
    `t3`.`Id4`
FROM 
    `sample` AS `s`
INNER JOIN 
    (SELECT `s0`.`Id` 
     FROM `sampletype` AS `s0` 
     WHERE NOT (`s0`.`IsDeleted`)
    ) AS `t` 
    ON `s`.`SampleTypeId` = `t`.`Id`
LEFT JOIN 
    (SELECT `u`.`Id` 
     FROM `useraccount` AS `u` 
     WHERE NOT (`u`.`IsDeleted`)
    ) AS `t0` 
    ON `s`.`ValidationUserAccountId` = `t0`.`Id`
INNER JOIN 
    (SELECT `p`.`Id`, `p`.`OperatorId`, `p`.`AssemblyId`, `p`.`AssemblyLocationId` 
     FROM `assemblyorder` AS `p` 
     WHERE NOT (`p`.`IsDeleted`)
    ) AS `t1` 
    ON `s`.`AssemblyOrderId` = `t1`.`Id`
INNER JOIN 
    `assembly` AS `p0` 
    ON `t1`.`AssemblyId` = `p0`.`Id`
LEFT JOIN 
    `assemblydetail` AS `p1` 
    ON `p0`.`Id` = `p1`.`AssemblyId`
LEFT JOIN 
    `assemblytitle` AS `p2` 
    ON `p1`.`AssemblyTitleId` = `p2`.`Id`
LEFT JOIN 
    `assemblytitleset` AS `p3` 
    ON `p2`.`AssemblyTitleSetId` = `p3`.`Id`
INNER JOIN 
    `polarity` AS `g` 
    ON `p0`.`PolarityId` = `g`.`Id`
LEFT JOIN 
    `operator` AS `d` 
    ON `t1`.`OperatorId` = `d`.`Id`
LEFT JOIN 
    `assemblylocation` AS `p4` 
    ON `t1`.`AssemblyLocationId` = `p4`.`Id`
LEFT JOIN 
    (SELECT `d0`.`Id` 
     FROM `subunit` AS `d0` 
     WHERE NOT (`d0`.`IsDeleted`)
    ) AS `t2` 
    ON `p4`.`SubunitId` = `t2`.`Id`
INNER JOIN 
    (SELECT `t4`.`Id`, `t4`.`SampleId`, `a`.`Id` AS `Id0`, 
            `a0`.`ExamSettingVersionId` AS `ExamSettingVersionId0`,
            `a1`.`ExamSettingVersionId` AS `ExamSettingVersionId1`,
            `a2`.`ExamSettingVersionId` AS `ExamSettingVersionId2`,
            `t5`.`Id` AS `Id1`, `a3`.`Id` AS `Id2`, `r`.`Id` AS `Id3`, 
            `t6`.`Id` AS `Id4`
     FROM `test` AS `t4`
     INNER JOIN `analysissettingversion` AS `a` 
         ON `t4`.`ExamSettingVersionId` = `a`.`Id`
     LEFT JOIN `analysisresultsetting` AS `a0` 
         ON `a`.`Id` = `a0`.`ExamSettingVersionId`
     LEFT JOIN `analysiscalculformula` AS `a1` 
         ON `a`.`Id` = `a1`.`ExamSettingVersionId`
     LEFT JOIN `analysisdetail` AS `a2` 
         ON `a`.`Id` = `a2`.`ExamSettingVersionId`
     LEFT JOIN 
         (SELECT `u0`.`Id` 
          FROM `useraccount` AS `u0` 
          WHERE NOT (`u0`.`IsDeleted`)
         ) AS `t5` 
         ON `t4`.`TechnicalValidatorUserAccountId` = `t5`.`Id`
     LEFT JOIN `analyseridentifier` AS `a3` 
         ON `t4`.`ExaminerIdentifierId` = `a3`.`Id`
     LEFT JOIN `resultproducer` AS `r` 
         ON `t4`.`ResultProducerId` = `r`.`Id`
     LEFT JOIN 
         (SELECT `u1`.`Id` 
          FROM `useraccount` AS `u1` 
          WHERE NOT (`u1`.`IsDeleted`)
         ) AS `t6` 
         ON `r`.`UserAccountId` = `t6`.`Id`
     WHERE NOT (`t4`.`IsDeleted`) 
           AND NOT (`t4`.`IsArchived`)
    ) AS `t3` 
    ON `s`.`Id` = `t3`.`SampleId`
INNER JOIN 
    (SELECT `t8`.`TestId`, `t8`.`ExaminerFlagId`, `t9`.`Id`, 
            `t9`.`ExaminerId`, `t9`.`Code`, `t9`.`FlagTypeId`, 
            `t9`.`SKUTypeId`, `t9`.`IsBlocking`, `t9`.`IsDeleted`, 
            `t9`.`IsErrorCode`, `t9`.`IsSKURelated`, `t9`.`Label`
     FROM `testanalyserflag` AS `t8`
     INNER JOIN 
         (SELECT `a4`.`Id`, `a4`.`ExaminerId`, `a4`.`Code`, `a4`.`FlagTypeId`, 
                 `a4`.`SKUTypeId`, `a4`.`IsBlocking`, `a4`.`IsDeleted`, 
                 `a4`.`IsErrorCode`, `a4`.`IsSKURelated`, `a4`.`Label`
          FROM `analyserflag` AS `a4`
          WHERE NOT (`a4`.`IsDeleted`)
         ) AS `t9` 
         ON `t8`.`ExaminerFlagId` = `t9`.`Id`
    ) AS `t7` 
    ON `t3`.`Id` = `t7`.`TestId`
WHERE 
    NOT (`s`.`IsDeleted`) 
    AND `s`.`Id` IN (186, 188)
ORDER BY 
    `s`.`Id`, `t`.`Id`, `t0`.`Id`, `t1`.`Id`, `p0`.`Id`, `p1`.`AssemblyId`, 
    `p2`.`Id`, `p3`.`Id`, `g`.`Id`, `d`.`Id`, `p4`.`Id`, `t2`.`Id`, 
    `t3`.`Id`, `t3`.`Id0`, `t3`.`ExamSettingVersionId0`, 
    `t3`.`ExamSettingVersionId1`, `t3`.`ExamSettingVersionId2`, 
    `t3`.`Id1`, `t3`.`Id2`, `t3`.`Id3`, `t3`.`Id4`;
