tsql - sql select count -


i have 2 tables: calls , attachments , want display that's in calls table display whether call has attachments, - determining if there attachment record call_id in it. maybe there attachments, maybe there isn't.

calls
call_id
title
description

attachments
attach_id
attach_name
call_id

if write:

select call_id, title, description calls 

to give me list of calls....

how can include whether call record has attachment(s) or not?

thanks,

you can use outer join accomplish this:

select c.call_id, title, description, attach_name calls c left outer join attachments on c.call_id = a.call_id 

the above display (null) attach_name if no attachment found. can use isnull() supply default value if no attach_name found, such as:

select c.call_id, title, description,      isnull(attach_name, '(no attachment)') attach_name calls c left outer join attachments on c.call_id = a.call_id 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -