Wednesday, March 30, 2011

Calling SQL Geniuses!

Any SQL ninjas out there?  My brain hurts trying to work out the correct syntax for this, your help would be much appreciated!!


Any ideas?

It's part of a larger query I need to construct, so if you figure this part out I'll reward you with more satisfying puzzles - what a treat!

1 comments:

Mark Anderson Smith said...

select c.display_name 'contact', c1.display_name 'Emer Contact1', c2.display_name 'Emer Contact2' from DME d
inner join contact c on d.Entity_id = c.ID and
left outer join contact c1 on d.EC1 = c1.ID and
left outer join contact c2 on d.EC2 = c2.ID
where d.Entity_id = #parameter#

...should do it. There are other ways and it may depend on the database you are using.