Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating join on 2 tables both if 2nd table has entry or not

Status
Not open for further replies.

russellobrien

Programmer
May 14, 2003
28
0
0
GB
Help!

I have 2 tables, the first a "customer" with relevant details. I have a second table listing customer "calls". Some will have called, some not.
I need to join the tabel such that I create a column on the end of the customer details that says whether there was a call or not (and also it picks the earliest call date)

i.e:

CUSTOMER

NAME DETAILS
jon seattle
bob london
bill berlin

etc


CALLS

NAME DATE
jon 1/1/2004
jon 3/1/2004
bob 22/11/2003


which returns

CALLS_FROM_CUSTOMERS

NAME DETAILS CALL(y/n) DATE(if y)
jon seatlle y 1/1/4
bob london y 22/11/3
bill berlin n NULL



Any help much appreciated.

Russell
 
Hi Russel,

try this:
Code:
select customer.name, customer.details, calls.date 
from customer left join calls on customer.name = calls.name
 
Or this:

select name, details, temp1 as [call (y/n)], min(date) as [date (if y)]
from (select customer.name, customer.details, iif(isnull(calls.date),'n','y') as temp1, calls.date
from customer
left join calls
on customer.name = calls.name)
group by name, details, temp1
order by 4 desc;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top