SQL Multiple JOINS to same table

I've got this query:

SELECT  View_CMS_Tree_Joined.*, CONTENT_Event.*, act1.*, act2.*
FROM View_CMS_Tree_Joined  
INNER JOIN CONTENT_Event
ON View_CMS_Tree_Joined.DocumentForeignKeyValue = CONTENT_Event.[eventID]
LEFT JOIN custom_activity AS act1
ON CONTENT_Event.[EventActivity] = act1.[activityID]
LEFT JOIN custom_activity AS act2
ON CONTENT_Event.[EventActivity2] = act2.[activityID]

It is returning the correct data - but the field names returned for act1 and act2 are identical - which makes it impossible to distinguish between act1.field1 and act2.field1. I'm obviously doing something wrong here.

Thanks for any help.
asrisbeyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
avoid using .* ... you will need to put all the field names you need, with each time a distinct alias name

SELECT  View_CMS_Tree_Joined.*
, CONTENT_Event.*
, act1.activityid activityid1, act1.somefield somefield1 .... etc ...
, act2.activityid activityid2, act2.somefield somefield2 .... etc ...
FROM View_CMS_Tree_Joined  
INNER JOIN CONTENT_Event 
ON View_CMS_Tree_Joined.DocumentForeignKeyValue = CONTENT_Event.[eventID]
LEFT JOIN custom_activity AS act1
ON CONTENT_Event.[EventActivity] = act1.[activityID]
LEFT JOIN custom_activity AS act2
ON CONTENT_Event.[EventActivity2] = act2.[activityID]

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
asrisbeyAuthor Commented:
Another great solution from angellll - thanks, works a treat.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.