I have a left join between table1 and table2:
select table1.*, table2.contact, table2.telephone from table1
LEFT JOIN table2 On table1.CUSTOMER = table2.customer
... problem is table2 may occasionally have more than 1 entry for a customer (where the repcode is different in each record for the customer)... Instead of the join returning the transaction twice, I want it to only show 1 of the contact details (doesnt matter which record)... How could i do this?
Thanks in advancedoesn't matter which one? oh boy, let's pick the one with the lowest telephone number!!select table1.*
, table2.contact
, table2.telephone
from table1
LEFT
JOIN table2 as T2
On T2.customer = table1.CUSTOMER
and T2.telephone =
( select min(telephone)
from table2
where customer = table1.CUSTOMER )
No comments:
Post a Comment