>>>Hi,
>>>
>>>I am trying to limit LEFT JOIN to select only one record. By design the child table should have only one record but I ran into a case where user had two records (wrong but it happens). And when two records are selected the entire resulting query is wrong. So, for example, say I have the following query:
>>>
>>>
>>>select .... from Table1 left join Table2 on Table1.pk_field = Table2.pk_field
>>>
>>>
>>>How can I change (if possible) the ON expression so that if Table2 has more than one record that matches the Table1.pk_field, only one is selected? (It does not matter to me which one). TIA.
>>
>>SELECT TOP 1 ... ORDER BY Table1.pk_field
>
>I cannot change the SELECT part of my query (if understand your suggestion correctly). That is, the SELECT part (before FROM) involves many fields. Unless you mean that SELECT TOP 1 can be part of the LEFT JOIN expression.
>Thank you.
He means
select top 1 * from myTable LEFT JOIN myOtherTable on ... where ID = SomeID
If it's not broken, fix it until it is.
My Blog