Hopefully someone will have some ideas on how to do this. I'm
officially stumped.
I have two entities to join. Simplified descriptions follow:
The first has names and addresses (vwPersonAddres s) keyed by PersonID
(it is actually a view on two tables, but it works exactly as I want
it to, so all good there).
vwPersonAddress
--------------------
personID (PK)
addrType (PK)
fname
lname
addr1
city
st
entity 2 is a table that lists licenses and companies and is 1 to many
with vwPersonAddress (a person can have multiple licenses).
vwLicCo
---------
personID (PK)
licenseID (PK)
licNum
CompanyName (can be null)
Now the odd part, I want to join them - but only get the first or max
company name from entity 2 for a given person. In other words, the
customer doesn't care WHAT company name I put in the output, as long
as it's only 1 (doesn't create extra records) and belongs to that
person. OH - and to keep it interesting, not every person will have a
company name in that second table...
I've played around quite a bit with all the join types and not found a
way to say, "Join these two tables, outer join on table 2 but if there
IS a match, only give me one"... that 'give me only one' bit is why I
was looking at max() by the way.
What I'm doing right now is running my output query on
vwPersonAddress , then as I create a data file (programmatical ly) doing
another query FOR EACH ROW on vwLicCo and just grabbing the first
companyName, if any. As you might guess, performance is less than
stellar. ;-)
Any thoughts?
Comment