Since you have 20 columns, you must check every column.I believe this will perform much faster. Only 10 JOINS now, where there where 20 subqueries before.SELECT DISTINCT CASE WHEN p1.ItemClientRef IS NULL THEN NULL ELSE RecvUDf1 END AS RecvUDf1, CASE WHEN p1.ItemClientRef IS NULL THEN NULL ELSE ClientUDf1 END AS ClientUDf1, CASE WHEN p2.ItemClientRef IS NULL THEN NULL ELSE RecvUDf2 END AS RecvUDf2, CASE WHEN p2.ItemClientRef IS NULL THEN NULL ELSE ClientUDf2 END AS ClientUDf2, CASE WHEN p3.ItemClientRef IS NULL THEN NULL ELSE RecvUDf3 END AS RecvUDf3, CASE WHEN p3.ItemClientRef IS NULL THEN NULL ELSE ClientUDf3 END AS ClientUDf3, CASE WHEN p4.ItemClientRef IS NULL THEN NULL ELSE RecvUDf4 END AS RecvUDf4, CASE WHEN p4.ItemClientRef IS NULL THEN NULL ELSE ClientUDf4 END AS ClientUDf4, CASE WHEN p5.ItemClientRef IS NULL THEN NULL ELSE RecvUDf5 END AS RecvUDf5, CASE WHEN p5.ItemClientRef IS NULL THEN NULL ELSE ClientUDf5 END AS ClientUDf5, CASE WHEN p6.ItemClientRef IS NULL THEN NULL ELSE RecvUDf6 END AS RecvUDf6, CASE WHEN p6.ItemClientRef IS NULL THEN NULL ELSE ClientUDf6 END AS ClientUDf6, CASE WHEN p7.ItemClientRef IS NULL THEN NULL ELSE RecvUDf7 END AS RecvUDf7, CASE WHEN p7.ItemClientRef IS NULL THEN NULL ELSE ClientUDf7 END AS ClientUDf7, CASE WHEN p8.ItemClientRef IS NULL THEN NULL ELSE RecvUDf8 END AS RecvUDf8, CASE WHEN p8.ItemClientRef IS NULL THEN NULL ELSE ClientUDf8 END AS ClientUDf8, CASE WHEN p9.ItemClientRef IS NULL THEN NULL ELSE RecvUDf9 END AS RecvUDf9, CASE WHEN p9.ItemClientRef IS NULL THEN NULL ELSE ClientUDf9 END AS ClientUDf9, CASE WHEN p10.ItemClientRef IS NULL THEN NULL ELSE RecvUDf10 END AS RecvUDf10, CASE WHEN p10.ItemClientRef IS NULL THEN NULL ELSE ClientUDf10 END AS ClientUDf10FROM <YourTableNameHere> AS tLEFT JOIN tblItemPickFormat AS p1 ON p1.ItemClientRef = t.ItemClientRef AND p1.PickType = t.ClientUDF1LEFT JOIN tblItemPickFormat AS p2 ON p2.ItemClientRef = t.ItemClientRef AND p2.PickType = t.ClientUDF2LEFT JOIN tblItemPickFormat AS p3 ON p3.ItemClientRef = t.ItemClientRef AND p3.PickType = t.ClientUDF3LEFT JOIN tblItemPickFormat AS p4 ON p4.ItemClientRef = t.ItemClientRef AND p4.PickType = t.ClientUDF4LEFT JOIN tblItemPickFormat AS p5 ON p5.ItemClientRef = t.ItemClientRef AND p5.PickType = t.ClientUDF5LEFT JOIN tblItemPickFormat AS p6 ON p6.ItemClientRef = t.ItemClientRef AND p6.PickType = t.ClientUDF6LEFT JOIN tblItemPickFormat AS p7 ON p7.ItemClientRef = t.ItemClientRef AND p7.PickType = t.ClientUDF7LEFT JOIN tblItemPickFormat AS p8 ON p8.ItemClientRef = t.ItemClientRef AND p8.PickType = t.ClientUDF8LEFT JOIN tblItemPickFormat AS p9 ON p9.ItemClientRef = t.ItemClientRef AND p9.PickType = t.ClientUDF9LEFT JOIN tblItemPickFormat AS p10 ON p10.ItemClientRef = t.ItemClientRef AND p10.PickType = t.ClientUDF10
Peter LarssonHelsingborg, Sweden