Click to See Complete Forum and Search --> : [RESOLVED] joins and composite keys


DARTHTAMPON
09-25-2007, 04:34 PM
ok so i have

tab1
===============
companyid number version name .......

tab2
===============
name number version exe path..........

with data like

tab1
===============
4,34,"1.3.4", "bob"
6, 35,"1.3.7", "fred"

tab2
===============
4,34,"1.3.4", "bob.exe", "c:"
4,34,"1.3.4", "bobr.exe", "c:"

How do I query off of these tables to get a result set like


"1.3.4","bob","bob.exe", "c:"

I have tried inner joins, where in's, and everything else I could think of with no luck.

Is there a nice way to join 2 tables 1-m to get a result set?

if so how on earth do you do it?

tia

DARTHTAMPON
09-26-2007, 07:51 AM
hay I resolved this using an outer apply, didnt even know such a thing existed

select version, name, lic.exe, lic.path
from dbo.tab1 a
outer apply
(
select exe, path from tab2 e
where a.company = e.company and
a.number = e.number and
a.version = e.version
) as lic

mattyblah
09-28-2007, 12:19 AM
ansi sql provides the APPLY operator. What Relation Database Management System are you using, and what version?